_Ret_notnull_ MESHBEAM * CMesh::addBeam(_In_ MESHNODE * pNode1, _In_ MESHNODE * pNode2, _In_ nfDouble * pRadius1, _In_ nfDouble * pRadius2, _In_ nfInt32 * peCapMode1, _In_ nfInt32 * peCapMode2) { if ((!pNode1) || (!pNode2) || (!pRadius1) || (!pRadius2) || (!peCapMode1) || (!peCapMode2)) throw CNMRException(NMR_ERROR_INVALIDPARAM); if (pNode1 == pNode2) throw CNMRException(NMR_ERROR_DUPLICATENODE); MESHBEAM * pBeam; nfUint32 nBeamCount = getBeamCount(); if (nBeamCount > NMR_MESH_MAXBEAMCOUNT) throw CNMRException(NMR_ERROR_TOOMANYBEAMS); nfUint32 nNewIndex; pBeam = m_BeamLattice.m_Beams.allocData(nNewIndex); pBeam->m_nodeindices[0] = pNode1->m_index; pBeam->m_nodeindices[1] = pNode2->m_index; pBeam->m_index = nNewIndex; pBeam->m_radius[0] = *pRadius1; pBeam->m_radius[1] = *pRadius2; pBeam->m_capMode[0] = *peCapMode1; pBeam->m_capMode[1] = *peCapMode2; return pBeam; }
void CModelReaderNode100_Tex2DGroup::OnAttribute(_In_z_ const nfWChar * pAttributeName, _In_z_ const nfWChar * pAttributeValue) { __NMRASSERT(pAttributeName); __NMRASSERT(pAttributeValue); if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_TEX2DGROUP_ID) == 0) { if (m_nID != 0) throw CNMRException(NMR_ERROR_DUPLICATERESOURCEID); // Convert to integer and make a input and range check! m_nID = fnWStringToUint32(pAttributeValue); } else if (wcscmp(pAttributeName, XML_3MF_ATTRIBUTE_TEX2DGROUP_TEXTUREID) == 0) { if (m_nTextureID != 0) throw CNMRException(NMR_ERROR_DUPLICATERESOURCEID); // Convert to integer and make a input and range check! ModelResourceID nID = fnWStringToUint32(pAttributeValue); if (nID == 0) m_pWarnings->addException(CNMRException(NMR_ERROR_INVALIDMODELRESOURCE), mrwInvalidMandatoryValue); m_nTextureID = nID; } else m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ATTRIBUTE), mrwInvalidOptionalValue); }
LIB3MFMETHODIMP CCOMModelBuildItem::SetObjectTransform(_In_ MODELTRANSFORM * pmTransform) { try { if (!pmTransform) throw CNMRException(NMR_ERROR_INVALIDPOINTER); if (!m_pModelBuildItem.get()) throw CNMRException(NMR_ERROR_INVALIDBUILDITEM); NMATRIX3 mMatrix = fnMATRIX3_identity (); int i, j; for (i = 0; i < 3; i++) { for (j = 0; j < 4; j++) { mMatrix.m_fields[i][j] = pmTransform->m_fFields[i][j]; } } m_pModelBuildItem->setTransform(mMatrix); return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
void CModelWriter_3MF_Native::writePackageToStream(_In_ PExportStream pStream) { if (pStream.get() == nullptr) throw CNMRException(NMR_ERROR_INVALIDPARAM); if (m_pModel == nullptr) throw CNMRException(NMR_ERROR_NOMODELTOWRITE); // Write Model Stream POpcPackageWriter pPackageWriter = std::make_shared<COpcPackageWriter>(pStream); POpcPackagePart pModelPart = pPackageWriter->addPart(PACKAGE_3D_MODEL_URI); PXmlWriter_Native pXMLWriter = std::make_shared<CXmlWriter_Native>(pModelPart->getExportStream()); writeModelStream(pXMLWriter.get(), m_pModel); // add Root relationships pPackageWriter->addRootRelationship(generateRelationShipID(), PACKAGE_START_PART_RELATIONSHIP_TYPE, pModelPart.get()); // add Textures addTextureParts(m_pModel, pPackageWriter, pModelPart); // add Content Types pPackageWriter->addContentType(PACKAGE_3D_RELS_EXTENSION, PACKAGE_3D_RELS_CONTENT_TYPE); pPackageWriter->addContentType(PACKAGE_3D_MODEL_EXTENSION, PACKAGE_3D_MODEL_CONTENT_TYPE); pPackageWriter->addContentType(PACKAGE_3D_TEXTURE_EXTENSION, PACKAGE_TEXTURE_CONTENT_TYPE); pPackageWriter->addContentType(PACKAGE_3D_PNG_EXTENSION, PACKAGE_PNG_CONTENT_TYPE); pPackageWriter->addContentType(PACKAGE_3D_JPEG_EXTENSION, PACKAGE_JPG_CONTENT_TYPE); pPackageWriter->addContentType(PACKAGE_3D_JPG_EXTENSION, PACKAGE_JPG_CONTENT_TYPE); }
LIB3MFMETHODIMP CCOMModelWriter::WriteToFileUTF8(_In_z_ LPCSTR pwszFilename) { try { if (pwszFilename == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); if (m_pModelWriter.get() == nullptr) throw CNMRException(NMR_ERROR_RESOURCENOTFOUND); // Convert to UTF16 std::string sUTF8FileName(pwszFilename); std::wstring sUTF16FileName = fnUTF8toUTF16(sUTF8FileName); PExportStream pStream = fnCreateExportStreamInstance(sUTF16FileName.c_str()); m_pModelWriter->exportToStream(pStream); return handleSuccess(); } catch (CNMRException_Windows & WinException) { return handleNMRException(&WinException); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
_Ret_notnull_ MESHFACE * CMesh::addFace(_In_ MESHNODE * pNode1, _In_ MESHNODE * pNode2, _In_ MESHNODE * pNode3) { if ((!pNode1) || (!pNode2) || (!pNode3)) throw CNMRException(NMR_ERROR_INVALIDPARAM); if ((pNode1 == pNode2) || (pNode1 == pNode3) || (pNode2 == pNode3)) throw CNMRException(NMR_ERROR_DUPLICATENODE); MESHFACE * pFace; nfUint32 nFaceCount = getFaceCount (); if (nFaceCount > NMR_MESH_MAXFACECOUNT) throw CNMRException(NMR_ERROR_TOOMANYFACES); nfUint32 nNewIndex; pFace = m_Faces.allocData (nNewIndex); pFace->m_nodeindices[0] = pNode1->m_index; pFace->m_nodeindices[1] = pNode2->m_index; pFace->m_nodeindices[2] = pNode3->m_index; pFace->m_index = nNewIndex; if (m_pMeshInformationHandler) m_pMeshInformationHandler->addFace(getFaceCount ()); return pFace; }
LIB3MFMETHODIMP CCOMModelBuildItem::GetPartNumber(_Out_opt_ LPWSTR pwszBuffer, _In_ ULONG cbBufferSize, _Out_opt_ ULONG * pcbNeededChars) { try { if (!m_pModelBuildItem.get()) throw CNMRException(NMR_ERROR_INVALIDBUILDITEM); if (cbBufferSize > MODEL_MAXSTRINGBUFFERLENGTH) throw CNMRException(NMR_ERROR_INVALIDBUFFERSIZE); // Safely call StringToBuffer nfUint32 nNeededChars = 0; fnWStringToBufferSafe(m_pModelBuildItem->getPartNumber(), pwszBuffer, cbBufferSize, &nNeededChars); // Return length if needed if (pcbNeededChars) *pcbNeededChars = nNeededChars; return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
CXmlWriter_COM::CXmlWriter_COM(_In_ PExportStream pExportStream) : CXmlWriter(pExportStream) { HRESULT hResult; if (pExportStream.get() == nullptr) throw CNMRException(NMR_ERROR_INVALIDPARAM); // Create XML Writer hResult = CreateXmlWriter(__uuidof(IXmlWriter), (void**)&m_pXMLWriter, nullptr); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_COULDNOTCREATEXMLWRITER, hResult); // Cast to COM Streams CExportStream_COM * pCOMExportStream = dynamic_cast<CExportStream_COM *> (pExportStream.get()); if (pCOMExportStream == nullptr) throw CNMRException(NMR_ERROR_INVALIDSTREAMTYPE); m_pCOMStream = pCOMExportStream->getCOMStream(); // Set XML Writer Output hResult = m_pXMLWriter->SetOutput(m_pCOMStream); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_COULDNOTSETXMLOUTPUT, hResult); // Set XML Writer Property hResult = m_pXMLWriter->SetProperty(XmlWriterProperty_Indent, true); if (hResult != S_OK) throw CNMRException_Windows(NMR_ERROR_COULDNOTSETXMLPROPERTY, hResult); }
LIB3MFMETHODIMP CCOMModelTexture2D::WriteToCallback(_In_ void * pWriteCallback, _In_opt_ void * pUserData) { try { if (pWriteCallback == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); PImportStream pTextureAttachment = pTextureResource->getTextureStream(); ExportStream_WriteCallbackType pTypedWriteCallback = (ExportStream_WriteCallbackType)pWriteCallback; if (pTextureAttachment.get() != nullptr) { PExportStream pExportStream = std::make_shared<CExportStream_Callback>(pTypedWriteCallback, nullptr, pUserData); pExportStream->copyFrom(pTextureAttachment.get(), pTextureAttachment->retrieveSize(), MODELTEXTURE2D_BUFFERSIZE); } else { throw CNMRException(NMR_ERROR_NOTEXTURESTREAM); } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelTexture2D::WriteToBuffer(_Out_ BYTE * pBuffer, _In_ ULONG64 cbBufferSize) { try { if (pBuffer == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); PImportStream pTextureStream = pTextureResource->getTextureStream(); if (pTextureStream.get() != nullptr) { nfUint64 cbStreamSize = pTextureStream->retrieveSize(); if (cbStreamSize > cbBufferSize) throw CNMRException(NMR_ERROR_INSUFFICIENTBUFFERSIZE); pTextureStream->seekPosition(0, true); pTextureStream->readBuffer(pBuffer, cbStreamSize, true); } else { throw CNMRException(NMR_ERROR_NOTEXTURESTREAM); } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelTexture2D::SetAttachment(_In_ ILib3MFModelAttachment * pTextureAttachment) { try { if (pTextureAttachment == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); // check relationship type std::string sRelationshipType; ULONG cbNeededChars; pTextureAttachment->GetRelationshipTypeUTF8(nullptr, 0, &cbNeededChars); sRelationshipType.resize(cbNeededChars); pTextureAttachment->GetRelationshipTypeUTF8(&(sRelationshipType[0]), cbNeededChars + 1, &cbNeededChars); if (!(sRelationshipType == PACKAGE_TEXTURE_RELATIONSHIP_TYPE)) throw CNMRException(NMR_ERROR_INVALIDRELATIONSHIPTYPEFORTEXTURE); std::string sPath; pTextureAttachment->GetPathUTF8(nullptr, 0, &cbNeededChars); sPath.resize(cbNeededChars); pTextureAttachment->GetPathUTF8(&(sPath[0]), cbNeededChars+1, &cbNeededChars); pTextureResource->setPath(sPath); return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelTexture2D::WriteToFile(_In_z_ LPCWSTR pwszFilename) { try { if (pwszFilename == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); PImportStream pTextureStream = pTextureResource->getTextureStream(); if (pTextureStream.get() != nullptr) { pTextureStream->writeToFile(pwszFilename); } else { throw CNMRException(NMR_ERROR_NOTEXTURESTREAM); } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
COpcPackageRelationshipReader::COpcPackageRelationshipReader(_In_ PImportStream pImportStream) { if (pImportStream.get() == nullptr) throw CNMRException(NMR_ERROR_INVALIDPARAM); PXmlReader pXMLReader = fnCreateXMLReaderInstance(pImportStream); eXmlReaderNodeType NodeType; // Read all XML Root Nodes while (!pXMLReader->IsEOF()) { if (!pXMLReader->Read(NodeType)) break; // Get Node Name LPCWSTR pwszLocalName = nullptr; pXMLReader->GetLocalName(&pwszLocalName, nullptr); if (!pwszLocalName) throw CNMRException(NMR_ERROR_COULDNOTGETLOCALXMLNAME); // Compare with Model Node Name if (wcscmp(pwszLocalName, OPC_RELS_RELATIONSHIP_CONTAINER) == 0) { parseRootNode(pXMLReader.get()); } } }
void CMeshBuilder::addToMesh(_In_ CMesh * pMesh, _In_ nfBool bIgnoreInvalidFaces) { nfUint32 nIdx, j; if (!pMesh) throw CNMRException(NMR_ERROR_INVALIDPARAM); std::vector<MESHNODE *> pNodes; nfUint32 nNodeCount = m_Nodes.getCount(); nfUint32 nFaceCount = m_Faces.getCount(); pNodes.resize(nNodeCount); for (nIdx = 0; nIdx < nNodeCount; nIdx++) { NVEC3 * pPosition = m_Nodes.getData(nIdx); pNodes[nIdx] = pMesh->addNode(*pPosition); } for (nIdx = 0; nIdx < nFaceCount; nIdx++) { NVEC3I * pFaceVec = m_Faces.getData(nIdx); MESHNODE * pNewNodes[3]; for (j = 0; j < 3; j++) { pNewNodes[j] = pNodes[pFaceVec->m_fields[j]]; } if ((pNewNodes[0] == pNewNodes[1]) || (pNewNodes[0] == pNewNodes[2]) || (pNewNodes[1] == pNewNodes[2])) { if (!bIgnoreInvalidFaces) throw CNMRException(NMR_ERROR_DUPLICATENODE); } else { pMesh->addFace(pNewNodes[0], pNewNodes[1], pNewNodes[2]); } } }
LIB3MFMETHODIMP CCOMModelTexture2D::WriteToFileUTF8(_In_z_ LPCSTR pszFilename) { try { if (pszFilename == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); PImportStream pTextureAttachment = pTextureResource->getTextureStream(); if (pTextureAttachment.get() != nullptr) { std::string sUTF8FileName(pszFilename); std::wstring sUTF16FileName = fnUTF8toUTF16(sUTF8FileName); pTextureAttachment->writeToFile(sUTF16FileName.c_str()); } else { throw CNMRException(NMR_ERROR_NOTEXTURESTREAM); } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
void CVectorTree::setUnits(_In_ nfFloat fUnits) { if ((fUnits < NMR_VECTOR_MINUNITS) || (fUnits > NMR_VECTOR_MAXUNITS)) throw CNMRException(NMR_ERROR_INVALIDUNITS); if (m_entries.size() > 0) throw CNMRException(NMR_ERROR_COULDNOTSETUNITS); m_fUnits = fUnits; }
void CModelReaderNode::parseContent(_In_ CXmlReader * pXMLReader) { __NMRASSERT(pXMLReader); if (m_sName == L"") throw CNMRException(NMR_ERROR_NODENAMEISEMPTY); if (m_bParsedContent) throw CNMRException(NMR_ERROR_ALREADYPARSEDXMLNODE); m_bParsedContent = true; if (m_bIsEmptyElement) return; while (!pXMLReader->IsEOF()) { LPCWSTR pwszQualifiedName = nullptr; LPCWSTR pwszText = nullptr; UINT nCount = 0; eXmlReaderNodeType NodeType; pXMLReader->Read(NodeType); switch (NodeType) { case XMLREADERNODETYPE_STARTELEMENT: pXMLReader->GetQualifiedName(&pwszQualifiedName, &nCount); if (!pwszQualifiedName) throw CNMRException(NMR_ERROR_COULDNOTGETQUALIFIEDXMLNAME); if (nCount > 0) OnChildElement(pwszQualifiedName, pXMLReader); break; case XMLREADERNODETYPE_TEXT: pXMLReader->GetValue(&pwszText, &nCount); if (!pwszText) throw CNMRException(NMR_ERROR_COULDNOTGETXMLTEXT); if (nCount > 0) OnText(pwszText, pXMLReader); break; case XMLREADERNODETYPE_ENDELEMENT: pXMLReader->GetQualifiedName(&pwszQualifiedName, &nCount); if (!pwszQualifiedName) throw CNMRException(NMR_ERROR_COULDNOTGETQUALIFIEDXMLNAME); if (wcscmp(pwszQualifiedName, m_sName.c_str()) == 0) { OnEndElement (pXMLReader); return; } break; case XMLREADERNODETYPE_UNKNOWN: break; } } }
void CModelReaderNode093_Color::parseColor() { m_cColor = 0; try { if (m_sColorString.length() > 0) { nfWChar bFirstChar = m_sColorString[0]; if (bFirstChar == L'#') { if (fnWStringToSRGBColor(m_sColorString.c_str(), m_cColor)) { return; } } if (bFirstChar == L's') { std::wstring sSubStr = m_sColorString.substr(0, 5); if (sSubStr == L"scRGB") { // parse scRGB String throw CNMRException(NMR_ERROR_NOTIMPLEMENTED); } } if (bFirstChar == L't') { std::wstring sSubStr = m_sColorString.substr(0, 4); if (sSubStr == L"tex(") { // parse Texture String if (m_sColorString.length() > 4) { std::wstring sTexID = m_sColorString.substr(4, m_sColorString.length() - sSubStr.length() - 1); nfInt32 nValue = fnWStringToInt32(sTexID.c_str()); if ((nValue < 0) || (nValue >= XML_3MF_MAXRESOURCEINDEX)) throw CNMRException(NMR_ERROR_INVALIDTEXTUREREFERENCE); m_nTextureID = nValue + 1; } else { throw CNMRException(NMR_ERROR_INVALIDTEXTUREREFERENCE); } } } if (bFirstChar == L'C') { std::wstring sSubStr4 = m_sColorString.substr(0, 4); if (sSubStr4 == L"CMYK") { throw CNMRException(NMR_ERROR_NOTSUPPORTINGLEGACYCMYK); } } } throw CNMRException(NMR_ERROR_INVALIDVALUEINCOLORSTRING); } catch (CNMRException & Exception) { m_pWarnings->addException(Exception, mrwMissingMandatoryValue); } }
COpcPackageReader::COpcPackageReader(_In_ PImportStream pImportStream) { if (pImportStream.get() == nullptr) throw CNMRException(NMR_ERROR_INVALIDPARAM); m_ZIPError.str = nullptr; m_ZIPError.sys_err = 0; m_ZIPError.zip_err = 0; m_ZIParchive = nullptr; m_ZIPsource = nullptr; try { // determine stream size nfUint64 nStreamSize = pImportStream->retrieveSize(); pImportStream->seekPosition(0, true); if (nStreamSize == 0) throw CNMRException(NMR_ERROR_COULDNOTGETSTREAMPOSITION); // read ZIP into memory m_Buffer.resize ((size_t) nStreamSize); pImportStream->readBuffer(&m_Buffer[0], nStreamSize, true); // create ZIP objects zip_error_init(&m_ZIPError); m_ZIPsource = zip_source_buffer_create(&m_Buffer[0], (size_t) nStreamSize, 0, &m_ZIPError); if (m_ZIPsource == nullptr) throw CNMRException(NMR_ERROR_COULDNOTREADZIPFILE); m_ZIParchive = zip_open_from_source(m_ZIPsource, ZIP_RDONLY | ZIP_CHECKCONS, &m_ZIPError); if (m_ZIParchive == nullptr) throw CNMRException(NMR_ERROR_COULDNOTREADZIPFILE); // Get ZIP Content nfInt64 nEntryCount = zip_get_num_entries(m_ZIParchive, ZIP_FL_UNCHANGED); if (nEntryCount < 0) throw CNMRException(NMR_ERROR_COULDNOTREADZIPFILE); // List Entries nfInt64 nIndex; for (nIndex = 0; nIndex < nEntryCount; nIndex++) { const char * pszName = zip_get_name(m_ZIParchive, (nfUint64) nIndex, ZIP_FL_ENC_GUESS); std::string sUTF8Name(pszName); std::wstring sUTF16Name = fnUTF8toUTF16(sUTF8Name); m_ZIPEntries.insert(std::make_pair(sUTF16Name, nIndex)); } readContentTypes(); readRootRelationships(); } catch (...) { releaseZIP(); throw; } }
// Build Handling void CModel::addBuildItem(_In_ PModelBuildItem pBuildItem) { if (!pBuildItem.get()) throw CNMRException(NMR_ERROR_INVALIDPARAM); if (m_BuildItems.size() >= XML_3MF_MAXBUILDITEMCOUNT) throw CNMRException(NMR_ERROR_INVALIDBUILDITEMCOUNT); m_BuildItems.push_back(pBuildItem); }
void COpcPackageRelationshipReader::parseChildNode(_In_ CXmlReader * pXMLReader) { if (pXMLReader == nullptr) throw CNMRException(NMR_ERROR_INVALIDPARAM); if (!pXMLReader->MoveToFirstAttribute()) return; std::wstring sTarget; std::wstring sID; std::wstring sType; nfBool bContinue = true; while (bContinue) { if (!pXMLReader->IsDefault()) { LPCWSTR pwszLocalName = nullptr; LPCWSTR pwszNameSpaceURI = nullptr; LPCWSTR pwszValue = nullptr; UINT nNameCount = 0; UINT nValueCount = 0; UINT nNameSpaceCount = 0; // Get Attribute Name pXMLReader->GetNamespaceURI(&pwszNameSpaceURI, &nNameSpaceCount); if (!pwszNameSpaceURI) throw CNMRException(NMR_ERROR_COULDNOTGETNAMESPACE); pXMLReader->GetLocalName(&pwszLocalName, &nNameCount); if (!pwszLocalName) throw CNMRException(NMR_ERROR_COULDNOTGETLOCALXMLNAME); // Get Attribute Value pXMLReader->GetValue(&pwszValue, &nValueCount); if (!pwszValue) throw CNMRException(NMR_ERROR_COULDNOTGETXMLVALUE); if (nNameSpaceCount == 0) { if (wcscmp(pwszLocalName, OPC_RELS_ATTRIB_TARGET) == 0) sTarget = pwszValue; if (wcscmp(pwszLocalName, OPC_RELS_ATTRIB_TYPE) == 0) sType = pwszValue; if (wcscmp(pwszLocalName, OPC_RELS_ATTRIB_ID) == 0) sID = pwszValue; } } bContinue = pXMLReader->MoveToNextAttribute(); } POpcPackageRelationship pRelationShip = std::make_shared<COpcPackageRelationship> (sID, sType, sTarget); m_RelationShips.push_back(pRelationShip); pXMLReader->CloseElement(); }
COpcPackagePart::COpcPackagePart(_In_ std::string sURI, _In_ PImportStream pImportStream) { if (pImportStream.get() == nullptr) throw CNMRException(NMR_ERROR_INVALIDPARAM); if (sURI.length() == 0) throw CNMRException(NMR_ERROR_INVALIDOPCPARTURI); m_sURI = sURI; m_pImportStream = pImportStream; }
LIB3MFMETHODIMP CCOMModelComponentsObject::AddComponent(_In_ ILib3MFModelObjectResource * pObject, _In_opt_ MODELTRANSFORM * pmTransform, _Outptr_ ILib3MFModelComponent ** ppComponent) { try { if (!pObject) throw CNMRException (NMR_ERROR_INVALIDPOINTER); CModelComponentsObject * pComponentsObject = getComponentsObject(); CModel * pModel = pComponentsObject->getModel(); __NMRASSERT(pModel); // Get Resource ID ModelResourceID nObjectID; HRESULT hResult = pObject->GetResourceID(&nObjectID); if (hResult != LIB3MF_OK) return hResult; // Find class instance CModelObject * pObject = pModel->findObject(nObjectID); if (pObject == nullptr) throw CNMRException(NMR_ERROR_RESOURCENOTFOUND); // Convert Transform, if given NMATRIX3 mMatrix = fnMATRIX3_identity(); if (pmTransform) { int i, j; for (i = 0; i < 3; i++) { for (j = 0; j < 4; j++) { mMatrix.m_fields[i][j] = pmTransform->m_fFields[i][j]; } } } // Create Model component PModelComponent pNewComponent = std::make_shared<CModelComponent>(pObject, mMatrix); pComponentsObject->addComponent(pNewComponent); // Create Component COM Wrapper if (ppComponent) { CCOMObject<CCOMModelComponent> * pResult = new CCOMObject<CCOMModelComponent>(); pResult->AddRef(); pResult->setComponent(pNewComponent); *ppComponent = pResult; } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
void CModelWriter_3MF_Native::writePackageToStream(_In_ PExportStream pStream) { if (pStream.get() == nullptr) throw CNMRException(NMR_ERROR_INVALIDPARAM); if (m_pModel == nullptr) throw CNMRException(NMR_ERROR_NOMODELTOWRITE); // Write Model Stream POpcPackageWriter pPackageWriter = std::make_shared<COpcPackageWriter>(pStream); POpcPackagePart pModelPart = pPackageWriter->addPart(PACKAGE_3D_MODEL_URI); PXmlWriter_Native pXMLWriter = std::make_shared<CXmlWriter_Native>(pModelPart->getExportStream()); writeModelStream(pXMLWriter.get(), m_pModel); // add Root relationships pPackageWriter->addRootRelationship(generateRelationShipID(), PACKAGE_START_PART_RELATIONSHIP_TYPE, pModelPart.get()); PModelAttachment pPackageThumbnail = m_pModel->getPackageThumbnail(); if (pPackageThumbnail.get() != nullptr) { // create Package Thumbnail Part POpcPackagePart pThumbnailPart = pPackageWriter->addPart(pPackageThumbnail->getPathURI()); PExportStream pExportStream = pThumbnailPart->getExportStream(); // Copy data PImportStream pPackageThumbnailStream = pPackageThumbnail->getStream(); pPackageThumbnailStream->seekPosition(0, true); pExportStream->copyFrom(pPackageThumbnailStream.get(), pPackageThumbnailStream->retrieveSize(), MODELWRITER_NATIVE_BUFFERSIZE); // add root relationship pPackageWriter->addRootRelationship(generateRelationShipID(), pPackageThumbnail->getRelationShipType(), pThumbnailPart.get()); } // add slicestacks that reference other files addSlicerefAttachments(m_pModel); // add Attachments addAttachments(m_pModel, pPackageWriter, pModelPart); // add Content Types pPackageWriter->addContentType(PACKAGE_3D_RELS_EXTENSION, PACKAGE_3D_RELS_CONTENT_TYPE); pPackageWriter->addContentType(PACKAGE_3D_MODEL_EXTENSION, PACKAGE_3D_MODEL_CONTENT_TYPE); pPackageWriter->addContentType(PACKAGE_3D_TEXTURE_EXTENSION, PACKAGE_TEXTURE_CONTENT_TYPE); pPackageWriter->addContentType(PACKAGE_3D_PNG_EXTENSION, PACKAGE_PNG_CONTENT_TYPE); pPackageWriter->addContentType(PACKAGE_3D_JPEG_EXTENSION, PACKAGE_JPG_CONTENT_TYPE); pPackageWriter->addContentType(PACKAGE_3D_JPG_EXTENSION, PACKAGE_JPG_CONTENT_TYPE); std::map<std::wstring, std::wstring> CustomContentTypes = m_pModel->getCustomContentTypes(); std::map<std::wstring, std::wstring>::iterator iContentTypeIterator; for (iContentTypeIterator = CustomContentTypes.begin(); iContentTypeIterator != CustomContentTypes.end(); iContentTypeIterator++) { if (!m_pModel->contentTypeIsDefault(iContentTypeIterator->first)) { pPackageWriter->addContentType(iContentTypeIterator->first, iContentTypeIterator->second); } } }
_Ret_notnull_ CModelComponentsObject * CCOMModelComponentsObject::getComponentsObject() { if (m_pResource.get() == nullptr) throw CNMRException(NMR_ERROR_INVALIDMESH); CModelComponentsObject * pComponentsObject = dynamic_cast<CModelComponentsObject *> (m_pResource.get()); if (pComponentsObject == nullptr) throw CNMRException(NMR_ERROR_INVALIDCOMPONENT); return pComponentsObject; }
void COpcPackageRelationshipReader::parseRootNode(_In_ CXmlReader * pXMLReader) { if (pXMLReader == nullptr) throw CNMRException(NMR_ERROR_INVALIDPARAM); parseAttributes(pXMLReader); while (!pXMLReader->IsEOF()) { LPCWSTR pwszLocalName = nullptr; LPCWSTR pwszNameSpaceURI = nullptr; UINT nCount = 0; UINT nNameSpaceCount = 0; eXmlReaderNodeType NodeType; pXMLReader->Read(NodeType); switch (NodeType) { case XMLREADERNODETYPE_STARTELEMENT: pXMLReader->GetLocalName(&pwszLocalName, &nCount); if (!pwszLocalName) throw CNMRException(NMR_ERROR_COULDNOTGETLOCALXMLNAME); pXMLReader->GetNamespaceURI(&pwszNameSpaceURI, &nNameSpaceCount); if (!pwszNameSpaceURI) throw CNMRException(NMR_ERROR_COULDNOTGETNAMESPACE); if (nCount > 0) { if (wcscmp(pwszNameSpaceURI, OPCPACKAGE_SCHEMA_RELATIONSHIPS) == 0) { if (wcscmp(pwszLocalName, OPC_RELS_RELATIONSHIP_NODE) == 0) { parseChildNode(pXMLReader); } } } break; case XMLREADERNODETYPE_ENDELEMENT: pXMLReader->GetLocalName(&pwszLocalName, &nCount); if (!pwszLocalName) throw CNMRException(NMR_ERROR_COULDNOTGETLOCALXMLNAME); if (wcscmp(pwszLocalName, OPC_RELS_RELATIONSHIP_CONTAINER) == 0) { return; } pXMLReader->CloseElement(); break; case XMLREADERNODETYPE_UNKNOWN: break; case XMLREADERNODETYPE_TEXT: break; } } }
_Ret_notnull_ CModelMeshObject * CCOMModelMeshObject::getMeshObject() { if (m_pResource.get() == nullptr) throw CNMRException(NMR_ERROR_INVALIDMESH); CModelMeshObject * pMeshObject = dynamic_cast<CModelMeshObject *> (m_pResource.get()); if (pMeshObject == nullptr) throw CNMRException(NMR_ERROR_INVALIDMESH); return pMeshObject; }
_Ret_notnull_ CModelTexture2DResource * CCOMModelTexture2D::getTexture2D() { if (m_pResource.get() == nullptr) throw CNMRException(NMR_ERROR_RESOURCENOTFOUND); CModelTexture2DResource * pTextureResource = dynamic_cast<CModelTexture2DResource *> (m_pResource.get()); if (pTextureResource == nullptr) throw CNMRException(NMR_ERROR_INVALIDTEXTURE); return pTextureResource; }
void CModelReaderNode093_Triangle::retrieveIndices(_Out_ nfInt32 & nIndex1, _Out_ nfInt32 & nIndex2, _Out_ nfInt32 & nIndex3, nfInt32 nNodeCount) { if ((m_nIndex1 < 0) || (m_nIndex2 < 0) || (m_nIndex3 < 0)) throw CNMRException(NMR_ERROR_INVALIDMODELNODEINDEX); if ((m_nIndex1 >= nNodeCount) || (m_nIndex2 >= nNodeCount) || (m_nIndex3 >= nNodeCount)) throw CNMRException(NMR_ERROR_INVALIDMODELNODEINDEX); nIndex1 = m_nIndex1; nIndex2 = m_nIndex2; nIndex3 = m_nIndex3; }
void CModelComponentsObject::addComponent(_In_ PModelComponent pComponent) { if (!pComponent) throw CNMRException(NMR_ERROR_INVALIDPARAM); CModel * pModel = getModel(); CModelObject * pModelObject = pComponent->getObject(); if (pModel != pModelObject->getModel()) throw CNMRException(NMR_ERROR_MODELMISMATCH); m_Components.push_back(pComponent); }