From a20198c1ab5e45f5b71bdcb786eb13d9061bf2ae Mon Sep 17 00:00:00 2001 From: Alexander Oster Date: Fri, 9 Jul 2021 19:53:44 +0200 Subject: [PATCH] Triangle Set Reader --- Include/Common/NMR_ErrorConst.h | 13 +++ Include/Model/Classes/NMR_ModelConstants.h | 1 + Include/Model/Classes/NMR_ModelMeshObject.h | 1 + .../Reader/v100/NMR_ModelReaderNode100_Mesh.h | 4 + .../v100/NMR_ModelReaderNode100_TriangleSet.h | 63 +++++++++++ .../NMR_ModelReaderNode100_TriangleSetRef.h | 55 ++++++++++ .../NMR_ModelReaderNode100_TriangleSets.h | 62 +++++++++++ Source/Common/NMR_Exception.cpp | 5 +- Source/Model/Classes/NMR_ModelMeshObject.cpp | 18 ++++ .../v100/NMR_ModelReaderNode100_Mesh.cpp | 18 ++++ .../v100/NMR_ModelReaderNode100_Object.cpp | 5 + .../NMR_ModelReaderNode100_TriangleSet.cpp | 97 +++++++++++++++++ .../NMR_ModelReaderNode100_TriangleSetRef.cpp | 89 +++++++++++++++ .../NMR_ModelReaderNode100_TriangleSets.cpp | 102 ++++++++++++++++++ 14 files changed, 532 insertions(+), 1 deletion(-) create mode 100644 Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSet.h create mode 100644 Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSetRef.h create mode 100644 Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.h create mode 100644 Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSet.cpp create mode 100644 Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSetRef.cpp create mode 100644 Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.cpp diff --git a/Include/Common/NMR_ErrorConst.h b/Include/Common/NMR_ErrorConst.h index 7b8cbf311..007b4f7e7 100644 --- a/Include/Common/NMR_ErrorConst.h +++ b/Include/Common/NMR_ErrorConst.h @@ -504,6 +504,19 @@ Core framework error codes (0x2XXX) // Too many triangle sets #define NMR_ERROR_TOOMANYTRIANGLESETS 0x2043 +// Invalid triangle set attribute +#define NMR_ERROR_TRIANGLESETINVALIDATTRIBUTE 0x2044 + +// Missing triangle set reference index +#define NMR_ERROR_TRIANGLESETMISSINGREFERENCEINDEX 0x2045 + +// Triangle set name missing +#define NMR_ERROR_TRIANGLESETNAMEMISSING 0x2046 + +// Triangle set identifier missing +#define NMR_ERROR_TRIANGLESETIDENTIFIERMISSING 0x2047 + + /*------------------------------------------------------------------- Model error codes (0x8XXX) -------------------------------------------------------------------*/ diff --git a/Include/Model/Classes/NMR_ModelConstants.h b/Include/Model/Classes/NMR_ModelConstants.h index f4751287b..b110fd649 100644 --- a/Include/Model/Classes/NMR_ModelConstants.h +++ b/Include/Model/Classes/NMR_ModelConstants.h @@ -194,6 +194,7 @@ These are given by the 3MF Standard #define XML_3MF_ATTRIBUTE_BEAMLATTICE_PRECISION "precision" #define XML_3MF_ATTRIBUTE_TRIANGLESET_IDENTIFIER "identifier" #define XML_3MF_ATTRIBUTE_TRIANGLESET_NAME "name" +#define XML_3MF_ATTRIBUTE_TRIANGLESETREF_INDEX "index" // Vertex element. #define XML_3MF_ELEMENT_VERTEX "vertex" diff --git a/Include/Model/Classes/NMR_ModelMeshObject.h b/Include/Model/Classes/NMR_ModelMeshObject.h index 59ca121b5..cc0ce6b37 100644 --- a/Include/Model/Classes/NMR_ModelMeshObject.h +++ b/Include/Model/Classes/NMR_ModelMeshObject.h @@ -94,6 +94,7 @@ namespace NMR { ResourceDependencies getDependencies() override; void deleteTriangleSet (_In_ CModelTriangleSet * pTriangleSet); PModelTriangleSet addTriangleSet(const std::string& sIdentifier, const std::string& sName); + PModelTriangleSet addTriangleSet(PModelTriangleSet pModelTriangleSet); PModelTriangleSet findTriangleSet (const std::string & sIdentifier); uint32_t getTriangleSetCount(); PModelTriangleSet getTriangleSet(const uint32_t nIndex); diff --git a/Include/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.h b/Include/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.h index 2bbb24dfd..51b50ac90 100644 --- a/Include/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.h +++ b/Include/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.h @@ -40,6 +40,7 @@ A mesh reader model node is a parser for the mesh node of an XML Model Stream. #include "Model/Classes/NMR_ModelObject.h" #include "Model/Classes/NMR_ModelVolumeData.h" #include "Model/Classes/NMR_ModelMeshObject.h" +#include "Model/Classes/NMR_ModelTriangleSet.h" namespace NMR { @@ -47,6 +48,7 @@ namespace NMR { private: PModelMeshObject m_pMesh; CModel * m_pModel; + std::vector m_pTriangleSets; ModelResourceID m_nObjectLevelPropertyID; PPackageResourceID m_pObjectLevelPropertyID; @@ -72,6 +74,8 @@ namespace NMR { virtual void parseXML(_In_ CXmlReader * pXMLReader); void retrieveClippingInfo(_Out_ eModelBeamLatticeClipMode &eClipMode, _Out_ nfBool & bHasClippingMode, _Out_ ModelResourceID & nClippingMeshID); void retrieveRepresentationInfo(_Out_ nfBool & bHasRepresentation, _Out_ ModelResourceID & nRepresentationMeshID); + + std::vector getTriangleSets (); }; typedef std::shared_ptr PModelReaderNode100_Mesh; } diff --git a/Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSet.h b/Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSet.h new file mode 100644 index 000000000..86a8c64b7 --- /dev/null +++ b/Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSet.h @@ -0,0 +1,63 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +--*/ + +#ifndef __NMR_MODELREADERNODE100_TRIANGLESET +#define __NMR_MODELREADERNODE100_TRIANGLESET + +#include "Model/Reader/NMR_ModelReaderNode.h" +#include "Model/Classes/NMR_ModelComponent.h" +#include "Model/Classes/NMR_ModelObject.h" +#include "Model/Classes/NMR_ModelTriangleSet.h" + +namespace NMR { + + class CModelReaderNode100_TriangleSet : public CModelReaderNode { + protected: + + std::string m_sName; + std::string m_sIdentifier; + + PModelTriangleSet m_pTriangleSet; + + virtual void OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue); + virtual void OnNSChildElement(_In_z_ const nfChar* pChildName, _In_z_ const nfChar* pNameSpace, _In_ CXmlReader* pXMLReader); + + public: + CModelReaderNode100_TriangleSet() = delete; + CModelReaderNode100_TriangleSet(_In_ PModelWarnings pWarnings); + + virtual void parseXML(_In_ CXmlReader * pXMLReader); + + PModelTriangleSet createTriangleSet(); + }; + + typedef std::shared_ptr PModelReaderNode100_TriangleSet; + +} + +#endif // __NMR_MODELREADERNODE100_TRIANGLESET diff --git a/Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSetRef.h b/Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSetRef.h new file mode 100644 index 000000000..2be0cc329 --- /dev/null +++ b/Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSetRef.h @@ -0,0 +1,55 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +--*/ + +#ifndef __NMR_MODELREADERNODE100_TRIANGLESETREF +#define __NMR_MODELREADERNODE100_TRIANGLESETREF + +#include "Model/Reader/NMR_ModelReaderNode.h" + +namespace NMR { + + class CModelReaderNode100_TriangleSetRef : public CModelReaderNode { + protected: + + uint32_t m_nIndex; + + virtual void OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue); + public: + CModelReaderNode100_TriangleSetRef() = delete; + CModelReaderNode100_TriangleSetRef(_In_ PModelWarnings pWarnings); + + virtual void parseXML(_In_ CXmlReader * pXMLReader); + + uint32_t getIndex(); + }; + + typedef std::shared_ptr PModelReaderNode100_TriangleSetRef; + +} + +#endif // __NMR_MODELREADERNODE100_TRIANGLESETREF diff --git a/Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.h b/Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.h new file mode 100644 index 000000000..d357c8eed --- /dev/null +++ b/Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.h @@ -0,0 +1,62 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +--*/ + +#ifndef __NMR_MODELREADERNODE100_TRIANGLESETS +#define __NMR_MODELREADERNODE100_TRIANGLESETS + +#include "Model/Reader/NMR_ModelReaderNode.h" +#include "Model/Classes/NMR_ModelComponent.h" +#include "Model/Classes/NMR_ModelObject.h" +#include "Model/Classes/NMR_ModelTriangleSet.h" + +namespace NMR { + + class CModelReaderNode100_TriangleSets : public CModelReaderNode { + protected: + CMesh * m_pMesh; + CModel * m_pModel; + + std::vector m_TriangleSets; + + virtual void OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue); + virtual void OnNSChildElement(_In_z_ const nfChar * pChildName, _In_z_ const nfChar * pNameSpace, _In_ CXmlReader * pXMLReader); + + public: + CModelReaderNode100_TriangleSets() = delete; + CModelReaderNode100_TriangleSets(_In_ CModel * pModel, _In_ CMesh * pMesh, _In_ PModelWarnings pWarnings); + + virtual void parseXML(_In_ CXmlReader * pXMLReader); + + std::vector getTriangleSets (); + }; + + typedef std::shared_ptr PModelReaderNode100_TriangleSets; + +} + +#endif // __NMR_MODELREADERNODE100_TRIANGLESETS diff --git a/Source/Common/NMR_Exception.cpp b/Source/Common/NMR_Exception.cpp index c297cb09f..706f8bb83 100644 --- a/Source/Common/NMR_Exception.cpp +++ b/Source/Common/NMR_Exception.cpp @@ -197,7 +197,10 @@ namespace NMR { case NMR_ERROR_INVALIDSLICEVERTEX: return "Invalid slice vertex index"; case NMR_ERROR_DUPLICATETRIANGLESET: return "Duplicate triangle set"; case NMR_ERROR_TOOMANYTRIANGLESETS: return "Too many triangle sets"; - + case NMR_ERROR_TRIANGLESETINVALIDATTRIBUTE: return "Invalid triangle set attribute"; + case NMR_ERROR_TRIANGLESETMISSINGREFERENCEINDEX: return "Missing triangle set reference index"; + case NMR_ERROR_TRIANGLESETNAMEMISSING: return "Triangle set name missing"; + case NMR_ERROR_TRIANGLESETIDENTIFIERMISSING : return "Triangle set identifier missing"; // Model error codes (0x8XXX) case NMR_ERROR_OPCREADFAILED: return "3MF Loading - OPC could not be loaded"; diff --git a/Source/Model/Classes/NMR_ModelMeshObject.cpp b/Source/Model/Classes/NMR_ModelMeshObject.cpp index 76f172e05..c318f1604 100644 --- a/Source/Model/Classes/NMR_ModelMeshObject.cpp +++ b/Source/Model/Classes/NMR_ModelMeshObject.cpp @@ -295,6 +295,24 @@ namespace NMR { } + PModelTriangleSet CModelMeshObject::addTriangleSet(PModelTriangleSet pModelTriangleSet) + { + if (pModelTriangleSet.get() == nullptr) + throw CNMRException(NMR_ERROR_INVALIDPARAM); + + auto iIterator = m_TriangleSetMap.find(pModelTriangleSet->getIdentifier()); + if (iIterator != m_TriangleSetMap.end()) + throw CNMRException(NMR_ERROR_DUPLICATETRIANGLESET); + + if (m_TriangleSets.size() >= TRIANGLESET_MAXCOUNT) + throw CNMRException(NMR_ERROR_TOOMANYTRIANGLESETS); + + m_TriangleSets.push_back(pModelTriangleSet); + m_TriangleSetMap.insert(std::make_pair(pModelTriangleSet->getIdentifier(), pModelTriangleSet)); + + return pModelTriangleSet; + } + uint32_t CModelMeshObject::getTriangleSetCount() { return (uint32_t)m_TriangleSets.size(); diff --git a/Source/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.cpp b/Source/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.cpp index 35bad5fd0..142947231 100644 --- a/Source/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.cpp +++ b/Source/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.cpp @@ -34,6 +34,7 @@ A mesh reader model node is a parser for the mesh node of an XML Model Stream. #include "Model/Reader/v100/NMR_ModelReaderNode100_Mesh.h" #include "Model/Reader/v100/NMR_ModelReaderNode100_Vertices.h" #include "Model/Reader/v100/NMR_ModelReaderNode100_Triangles.h" +#include "Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.h" #include "Model/Reader/BeamLattice1702/NMR_ModelReaderNode_BeamLattice1702_BeamLattice.h" #include "Model/Reader/Volumetric2201/NMR_ModelReaderNode_Volumetric2201_VolumeData.h" @@ -194,6 +195,23 @@ namespace NMR { m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ELEMENT), mrwInvalidOptionalValue); } + if (strcmp(pNameSpace, XML_3MF_NAMESPACE_TRIANGLESETS) == 0) { + if (strcmp(pChildName, XML_3MF_ELEMENT_TRIANGLESETS) == 0) + { + PModelReaderNode100_TriangleSets pXMLNode = std::make_shared(m_pModel, m_pMesh, m_pWarnings); + pXMLNode->parseXML(pXMLReader); + + m_pTriangleSets = pXMLNode->getTriangleSets (); + } + else + m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ELEMENT), mrwInvalidOptionalValue); + } + + } + + std::vector CModelReaderNode100_Mesh::getTriangleSets() + { + return m_pTriangleSets; } } diff --git a/Source/Model/Reader/v100/NMR_ModelReaderNode100_Object.cpp b/Source/Model/Reader/v100/NMR_ModelReaderNode100_Object.cpp index ef1d0d84f..2562abc2c 100644 --- a/Source/Model/Reader/v100/NMR_ModelReaderNode100_Object.cpp +++ b/Source/Model/Reader/v100/NMR_ModelReaderNode100_Object.cpp @@ -250,6 +250,11 @@ namespace NMR { m_pWarnings, m_pProgressMonitor, m_pObjectLevelPropertyID, m_nObjectLevelPropertyIndex); pXMLNode->parseXML(pXMLReader); + // store triangle sets in memory model + auto triangleSets = pXMLNode->getTriangleSets(); + for (auto triangleSet : triangleSets) + pModelMeshObject->addTriangleSet(triangleSet); + // Add Object to Parent m_pModel->addResource(m_pObject); diff --git a/Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSet.cpp b/Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSet.cpp new file mode 100644 index 000000000..c75b28c60 --- /dev/null +++ b/Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSet.cpp @@ -0,0 +1,97 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +--*/ + +#include "Model/Reader/v100/NMR_ModelReaderNode100_TriangleSet.h" +#include "Model/Reader/v100/NMR_ModelReaderNode100_TriangleSetRef.h" + +#include "Model/Classes/NMR_ModelConstants.h" +#include "Common/NMR_Exception.h" +#include "Common/NMR_Exception_Windows.h" +#include "Common/NMR_StringUtils.h" +#include +#include + +namespace NMR { + + CModelReaderNode100_TriangleSet::CModelReaderNode100_TriangleSet(_In_ PModelWarnings pWarnings) + : CModelReaderNode(pWarnings) + { + } + + void CModelReaderNode100_TriangleSet::parseXML(_In_ CXmlReader * pXMLReader) + { + // Parse name + parseName(pXMLReader); + + // Parse attribute + parseAttributes(pXMLReader); + + m_pTriangleSet = std::make_shared(m_sName, m_sIdentifier); + + // Parse Content + parseContent(pXMLReader); + } + + + void CModelReaderNode100_TriangleSet::OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue) + { + __NMRASSERT(pAttributeName); + __NMRASSERT(pAttributeValue); + + + } + + + + void CModelReaderNode100_TriangleSet::OnNSChildElement(_In_z_ const nfChar* pChildName, _In_z_ const nfChar* pNameSpace, _In_ CXmlReader* pXMLReader) + { + __NMRASSERT(pChildName); + __NMRASSERT(pXMLReader); + __NMRASSERT(pNameSpace); + + if (strcmp(pNameSpace, XML_3MF_NAMESPACE_TRIANGLESETS) == 0) { + if (strcmp(pChildName, XML_3MF_ELEMENT_TRIANGLESET) == 0) + { + PModelReaderNode100_TriangleSetRef pXMLNode = std::make_shared(m_pWarnings); + pXMLNode->parseXML(pXMLReader); + + m_pTriangleSet->addTriangle(pXMLNode->getIndex()); + } + else + m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ELEMENT), mrwInvalidOptionalValue); + } + + } + + + PModelTriangleSet CModelReaderNode100_TriangleSet::createTriangleSet() + { + return m_pTriangleSet; + } + +} diff --git a/Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSetRef.cpp b/Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSetRef.cpp new file mode 100644 index 000000000..4e5468706 --- /dev/null +++ b/Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSetRef.cpp @@ -0,0 +1,89 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +NMR_ModelReaderNode100_Triangle.cpp implements the Model Reader Triangle Node +Class. A triangle reader model node is a parser for the triangle node of an +XML Model Stream. + +--*/ + +#include "Model/Reader/v100/NMR_ModelReaderNode100_TriangleSetRef.h" + +#include "Model/Classes/NMR_ModelConstants.h" +#include "Common/NMR_Exception.h" +#include "Common/NMR_Exception_Windows.h" +#include "Common/NMR_StringUtils.h" +#include +#include + +namespace NMR { + + CModelReaderNode100_TriangleSetRef::CModelReaderNode100_TriangleSetRef(_In_ PModelWarnings pWarnings) + : CModelReaderNode(pWarnings), m_nIndex (0xffffffff) + { + } + + void CModelReaderNode100_TriangleSetRef::parseXML(_In_ CXmlReader * pXMLReader) + { + // Parse name + parseName(pXMLReader); + + // Parse attribute + parseAttributes(pXMLReader); + + // Parse Content + parseContent(pXMLReader); + } + + + void CModelReaderNode100_TriangleSetRef::OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue) + { + __NMRASSERT(pAttributeName); + __NMRASSERT(pAttributeValue); + + + if (strcmp(pAttributeName, XML_3MF_ATTRIBUTE_TRIANGLESETREF_INDEX) == 0) { + nfInt32 nValue = fnStringToInt32(pAttributeValue); + if ((nValue >= 0) && (nValue < XML_3MF_MAXRESOURCEINDEX)) + m_nIndex = nValue; + } + else + m_pWarnings->addException(CNMRException(NMR_ERROR_TRIANGLESETINVALIDATTRIBUTE), mrwInvalidMandatoryValue); + + } + + + uint32_t CModelReaderNode100_TriangleSetRef::getIndex() + { + if (m_nIndex >= XML_3MF_MAXRESOURCEINDEX) + m_pWarnings->addException(CNMRException(NMR_ERROR_TRIANGLESETMISSINGREFERENCEINDEX), mrwInvalidMandatoryValue); + + return m_nIndex; + } + +} diff --git a/Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.cpp b/Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.cpp new file mode 100644 index 000000000..593608bb6 --- /dev/null +++ b/Source/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.cpp @@ -0,0 +1,102 @@ +/*++ + +Copyright (C) 2019 3MF Consortium + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Abstract: + +NMR_ModelReaderNode100_Triangles.cpp implements the Model Reader Triangles Node +Class. A triangles reader model node is a parser for the triangles node of an +XML Model Stream. + +--*/ + +#include "Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.h" +#include "Model/Reader/v100/NMR_ModelReaderNode100_TriangleSet.h" + +#include "Model/Classes/NMR_ModelConstants.h" +#include "Common/NMR_StringUtils.h" +#include "Common/NMR_Exception.h" +#include "Common/NMR_Exception_Windows.h" + +namespace NMR { + + CModelReaderNode100_TriangleSets::CModelReaderNode100_TriangleSets(_In_ CModel * pModel, _In_ CMesh * pMesh, + _In_ PModelWarnings pWarnings) + : CModelReaderNode(pWarnings) + { + __NMRASSERT(pMesh); + __NMRASSERT(pModel); + + m_pModel = pModel; + m_pMesh = pMesh; + } + + void CModelReaderNode100_TriangleSets::parseXML(_In_ CXmlReader * pXMLReader) + { + // Parse Name + parseName(pXMLReader); + + // Parse attribute + parseAttributes(pXMLReader); + + // Parse Content + parseContent(pXMLReader); + } + + void CModelReaderNode100_TriangleSets::OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue) + { + __NMRASSERT(pAttributeName); + __NMRASSERT(pAttributeValue); + } + + + + void CModelReaderNode100_TriangleSets::OnNSChildElement(_In_z_ const nfChar * pChildName, _In_z_ const nfChar * pNameSpace, _In_ CXmlReader * pXMLReader) + { + __NMRASSERT(pChildName); + __NMRASSERT(pXMLReader); + __NMRASSERT(pNameSpace); + + if (strcmp(pNameSpace, XML_3MF_NAMESPACE_TRIANGLESETS) == 0) { + if (strcmp(pChildName, XML_3MF_ELEMENT_TRIANGLESET) == 0) + { + PModelReaderNode100_TriangleSet pXMLNode = std::make_shared(m_pWarnings); + pXMLNode->parseXML(pXMLReader); + + m_TriangleSets.push_back(pXMLNode->createTriangleSet ()); + + + } + else + m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ELEMENT), mrwInvalidOptionalValue); + } + + } + + std::vector CModelReaderNode100_TriangleSets::getTriangleSets() + { + return m_TriangleSets; + } +}