Skip to content

Commit

Permalink
Extract resource write methods
Browse files Browse the repository at this point in the history
  • Loading branch information
3dJan committed Oct 7, 2024
1 parent 52ab643 commit ecc6373
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 71 deletions.
1 change: 1 addition & 0 deletions Include/Model/Writer/NMR_ModelWriterNode_Implicit.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace NMR
PProgressMonitor pProgressMonitor);

void writeImplicitFunctions();
void writeImplicitFunction(CModelImplicitFunction & function);

void writeToXML() override;

Expand Down
5 changes: 5 additions & 0 deletions Include/Model/Writer/v100/NMR_ModelWriterNode100_Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ namespace NMR {
void writeMultiProperties();
void writeMultiPropertyAttributes(_In_ CModelMultiPropertyGroupResource* pMultiPropertyGroup);
void writeMultiPropertyMultiElements(_In_ CModelMultiPropertyGroupResource* pMultiPropertyGroup);

void writeImage3Ds();
void writeImage3D(CModelImage3D & pImage3D);

void writeFunctionsFromImage3D();
void writeFunctionFromImage3D(CModelFunctionFromImage3D & functionFromImage3D);

void writeImplicitFunctions();
void writeVolumeData();

Expand Down
2 changes: 1 addition & 1 deletion Source/Model/Classes/NMR_Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ namespace NMR {
return newResourceID;
}

void CModel::updateUniqueResourceID(UniqueResourceID nOldID, UniqueResourceID nNewID)
void CModel::updateUniqueResourceID(UniqueResourceID nOldID, UniqueResourceID nNewID)
{
if (m_ResourceMap.find(nNewID) != m_ResourceMap.end()) {
throw CNMRException(NMR_ERROR_DUPLICATEMODELRESOURCE);
Expand Down
26 changes: 16 additions & 10 deletions Source/Model/Writer/NMR_ModelWriterNode_Implicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,24 @@ namespace NMR
continue;
}

writeStartElementWithPrefix(XML_3MF_ELEMENT_IMPLICIT_FUNCTION,
XML_3MF_NAMESPACEPREFIX_IMPLICIT);
{
writeIntAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_FUNCTION_ID,
pFunction->getPackageResourceID()->getModelResourceID());
writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_FUNCTION_DISPLAY_NAME,
pFunction->getDisplayName());
writeImplicitFunction(*pFunction);
}
}

writeImplicitFunctionElements(*pFunction);
}
writeFullEndElement();
void CModelWriterNode_Implicit::writeImplicitFunction(
CModelImplicitFunction& function)
{
writeStartElementWithPrefix(XML_3MF_ELEMENT_IMPLICIT_FUNCTION,
XML_3MF_NAMESPACEPREFIX_IMPLICIT);
{
writeIntAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_FUNCTION_ID,
function.getPackageResourceID()->getModelResourceID());
writeStringAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_FUNCTION_DISPLAY_NAME,
function.getDisplayName());

writeImplicitFunctionElements(function);
}
writeFullEndElement();
}

void CModelWriterNode_Implicit::writeToXML()
Expand Down
137 changes: 77 additions & 60 deletions Source/Model/Writer/v100/NMR_ModelWriterNode100_Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,42 +817,52 @@ namespace NMR {
for (nfUint32 nIndex = 0; nIndex < nCount; nIndex++) {
CModelImage3D * pImage3DResource = m_pModel->getImage3D(nIndex);

writeStartElementWithPrefix(XML_3MF_ELEMENT_IMAGE3D, XML_3MF_NAMESPACEPREFIX_VOLUMETRIC);
writeIntAttribute(XML_3MF_ATTRIBUTE_IMAGE3D_ID, pImage3DResource->getPackageResourceID()->getModelResourceID());
if (!pImage3DResource->getName().empty())
writeStringAttribute(XML_3MF_ATTRIBUTE_IMAGE3D_NAME, pImage3DResource->getName());

if (CModelImageStack* pImageStack = dynamic_cast<CModelImageStack*>(pImage3DResource))
if (!pImage3DResource)
{
writeStartElementWithPrefix(XML_3MF_ELEMENT_IMAGESTACK, XML_3MF_NAMESPACEPREFIX_VOLUMETRIC);

nfUint32 nSheetCount = pImageStack->getSheetCount();
writeIntAttribute(XML_3MF_ATTRIBUTE_IMAGESTACK_ROWCOUNT, pImageStack->getRowCount());
writeIntAttribute(XML_3MF_ATTRIBUTE_IMAGESTACK_COLUMNCOUNT, pImageStack->getColumnCount());
writeIntAttribute(XML_3MF_ATTRIBUTE_IMAGESTACK_SHEETCOUNT, nSheetCount);

for (nfUint32 nSheetIndex = 0; nSheetIndex < nSheetCount; nSheetIndex++) {
auto pSheet = pImageStack->getSheet(nSheetIndex);
writeStartElementWithPrefix(XML_3MF_ELEMENT_IMAGESHEET, XML_3MF_NAMESPACEPREFIX_VOLUMETRIC);
if (pSheet.get() != nullptr) {
writeStringAttribute(XML_3MF_ATTRIBUTE_IMAGESHEET_PATH, pSheet->getPathURI());
}
writeEndElement();
}

writeFullEndElement();
throw CNMRException(NMR_ERROR_INVALID_RESOURCE_INDEX, "Invalid Image3D resource index.");
}
else
{
throw CNMRException(-1); // TODO NMR_ERROR_UNKNOWN_IMAGE3D_TYPE
writeImage3D(*pImage3DResource);
}

}

void CModelWriterNode100_Model::writeImage3D(CModelImage3D &pImage3D)
{
writeStartElementWithPrefix(XML_3MF_ELEMENT_IMAGE3D, XML_3MF_NAMESPACEPREFIX_VOLUMETRIC);
writeIntAttribute(XML_3MF_ATTRIBUTE_IMAGE3D_ID, pImage3D.getPackageResourceID()->getModelResourceID());
if (!pImage3D.getName().empty())
writeStringAttribute(XML_3MF_ATTRIBUTE_IMAGE3D_NAME, pImage3D.getName());

if (CModelImageStack* pImageStack = dynamic_cast<CModelImageStack*>(&pImage3D))
{
writeStartElementWithPrefix(XML_3MF_ELEMENT_IMAGESTACK, XML_3MF_NAMESPACEPREFIX_VOLUMETRIC);

nfUint32 nSheetCount = pImageStack->getSheetCount();
writeIntAttribute(XML_3MF_ATTRIBUTE_IMAGESTACK_ROWCOUNT, pImageStack->getRowCount());
writeIntAttribute(XML_3MF_ATTRIBUTE_IMAGESTACK_COLUMNCOUNT, pImageStack->getColumnCount());
writeIntAttribute(XML_3MF_ATTRIBUTE_IMAGESTACK_SHEETCOUNT, nSheetCount);

for (nfUint32 nSheetIndex = 0; nSheetIndex < nSheetCount; nSheetIndex++) {
auto pSheet = pImageStack->getSheet(nSheetIndex);
writeStartElementWithPrefix(XML_3MF_ELEMENT_IMAGESHEET, XML_3MF_NAMESPACEPREFIX_VOLUMETRIC);
if (pSheet.get() != nullptr) {
writeStringAttribute(XML_3MF_ATTRIBUTE_IMAGESHEET_PATH, pSheet->getPathURI());
}
writeEndElement();
}

writeFullEndElement();
}
else
{
throw CNMRException(-1); // TODO NMR_ERROR_UNKNOWN_IMAGE3D_TYPE
}

writeFullEndElement();
}

void CModelWriterNode100_Model::writeFunctionsFromImage3D()

void CModelWriterNode100_Model::writeFunctionsFromImage3D()
{
nfUint32 nCount = m_pModel->getFunctionCount();

Expand All @@ -863,42 +873,49 @@ namespace NMR {
{
continue;
}
writeStartElementWithPrefix(XML_3MF_ELEMENT_FUNCTION_FROM_IMAGE3D,
XML_3MF_NAMESPACEPREFIX_VOLUMETRIC);
{
writeIntAttribute(
XML_3MF_ATTRIBUTE_IMPLICIT_FUNCTION_ID,
funcFromImg3D->getPackageResourceID()->getModelResourceID());
writeStringAttribute(
XML_3MF_ATTRIBUTE_IMPLICIT_FUNCTION_DISPLAY_NAME,
funcFromImg3D->getDisplayName());
writeIntAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_IMAGE3DID,
funcFromImg3D->getImage3DModelResourceID());
writeDoubleAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_OFFSET,
funcFromImg3D->getOffset());
writeDoubleAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_SCALE,
funcFromImg3D->getScale());

writeStringAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_TILESTYLEU,
CModelTexture2DResource::tileStyleToString(funcFromImg3D->getTileStyleU()));
writeStringAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_TILESTYLEV,
CModelTexture2DResource::tileStyleToString(funcFromImg3D->getTileStyleV()));
writeStringAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_TILESTYLEW,
CModelTexture2DResource::tileStyleToString(funcFromImg3D->getTileStyleW()));
writeStringAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_FILTER,
CModelTexture2DResource::filterToString(funcFromImg3D->getFilter()));
}
writeFullEndElement();

writeFunctionFromImage3D(*funcFromImg3D);
}
}

void CModelWriterNode100_Model::writeFunctionFromImage3D(
CModelFunctionFromImage3D & functionFromImage3D)
{
writeStartElementWithPrefix(XML_3MF_ELEMENT_FUNCTION_FROM_IMAGE3D,
XML_3MF_NAMESPACEPREFIX_VOLUMETRIC);
writeIntAttribute(XML_3MF_ATTRIBUTE_IMPLICIT_FUNCTION_ID,
functionFromImage3D.getPackageResourceID()
->getModelResourceID());
writeStringAttribute(
XML_3MF_ATTRIBUTE_IMPLICIT_FUNCTION_DISPLAY_NAME,
functionFromImage3D.getDisplayName());
writeIntAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_IMAGE3DID,
functionFromImage3D.getImage3DModelResourceID());
writeDoubleAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_OFFSET,
functionFromImage3D.getOffset());
writeDoubleAttribute(XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_SCALE,
functionFromImage3D.getScale());
writeStringAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_TILESTYLEU,
CModelTexture2DResource::tileStyleToString(
functionFromImage3D.getTileStyleU()));
writeStringAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_TILESTYLEV,
CModelTexture2DResource::tileStyleToString(
functionFromImage3D.getTileStyleV()));
writeStringAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_TILESTYLEW,
CModelTexture2DResource::tileStyleToString(
functionFromImage3D.getTileStyleW()));
writeStringAttribute(
XML_3MF_ATTRIBUTE_FUNTCTION_FROM_IMAGE3D_FILTER,
CModelTexture2DResource::filterToString(
functionFromImage3D.getFilter()));
writeFullEndElement();
}

void CModelWriterNode100_Model::writeImplicitFunctions()
{
CModelWriterNode_Implicit implicitWriter(m_pModel, m_pXMLWriter, m_pProgressMonitor);
Expand Down

0 comments on commit ecc6373

Please sign in to comment.