Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ SetupWriteRead5.3mf
v093reout.3mf
.vs
.idea
cmake-build-*
cmake-build-*
build_test

11 changes: 11 additions & 0 deletions Autogenerated/Bindings/Cpp/lib3mf_abi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2923,6 +2923,17 @@ LIB3MF_DECLSPEC Lib3MFResult lib3mf_attachment_writetobuffer(Lib3MF_Attachment p
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_attachment_readfrombuffer(Lib3MF_Attachment pAttachment, Lib3MF_uint64 nBufferBufferSize, const Lib3MF_uint8 * pBufferBuffer);

/**
* Retrieves an attachment's content type
*
* @param[in] pAttachment - Attachment instance.
* @param[in] nContentTypeBufferSize - size of the buffer (including trailing 0)
* @param[out] pContentTypeNeededChars - will be filled with the count of the written bytes, or needed buffer size.
* @param[out] pContentTypeBuffer - buffer of returns the attachment's content type string, may be NULL
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_attachment_getcontenttype(Lib3MF_Attachment pAttachment, const Lib3MF_uint32 nContentTypeBufferSize, Lib3MF_uint32* pContentTypeNeededChars, char * pContentTypeBuffer);

/*************************************************************************************************************************
Class definition for Texture2D
**************************************************************************************************************************/
Expand Down
16 changes: 16 additions & 0 deletions Autogenerated/Bindings/Cpp/lib3mf_implicit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,7 @@ class CAttachment : public CBase {
inline Lib3MF_uint64 GetStreamSize();
inline void WriteToBuffer(std::vector<Lib3MF_uint8> & BufferBuffer);
inline void ReadFromBuffer(const CInputVector<Lib3MF_uint8> & BufferBuffer);
inline std::string GetContentType();
};

/*************************************************************************************************************************
Expand Down Expand Up @@ -7432,6 +7433,21 @@ inline CBase* CWrapper::polymorphicFactory(Lib3MFHandle pHandle)
CheckError(lib3mf_attachment_readfrombuffer(m_pHandle, nBufferSize, BufferBuffer.data()));
}

/**
* CAttachment::GetContentType - Retrieves an attachment's content type
* @return returns the attachment's content type string
*/
std::string CAttachment::GetContentType()
{
Lib3MF_uint32 bytesNeededContentType = 0;
Lib3MF_uint32 bytesWrittenContentType = 0;
CheckError(lib3mf_attachment_getcontenttype(m_pHandle, 0, &bytesNeededContentType, nullptr));
std::vector<char> bufferContentType(bytesNeededContentType);
CheckError(lib3mf_attachment_getcontenttype(m_pHandle, bytesNeededContentType, &bytesWrittenContentType, &bufferContentType[0]));

return std::string(&bufferContentType[0]);
}

/**
* Method definitions for class CTexture2D
*/
Expand Down
11 changes: 11 additions & 0 deletions Autogenerated/Bindings/CppDynamic/lib3mf_abi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3179,6 +3179,17 @@ LIB3MF_DECLSPEC Lib3MFResult lib3mf_attachment_writetobuffer(Lib3MF_Attachment p
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_attachment_readfrombuffer(Lib3MF_Attachment pAttachment, Lib3MF_uint64 nBufferBufferSize, const Lib3MF_uint8 * pBufferBuffer);

/**
* Retrieves an attachment's content type
*
* @param[in] pAttachment - Attachment instance.
* @param[in] nContentTypeBufferSize - size of the buffer (including trailing 0)
* @param[out] pContentTypeNeededChars - will be filled with the count of the written bytes, or needed buffer size.
* @param[out] pContentTypeBuffer - buffer of returns the attachment's content type string, may be NULL
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_attachment_getcontenttype(Lib3MF_Attachment pAttachment, const Lib3MF_uint32 nContentTypeBufferSize, Lib3MF_uint32* pContentTypeNeededChars, char * pContentTypeBuffer);

/*************************************************************************************************************************
Class definition for Texture2D
**************************************************************************************************************************/
Expand Down
12 changes: 12 additions & 0 deletions Autogenerated/Bindings/CppDynamic/lib3mf_dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2910,6 +2910,17 @@ typedef Lib3MFResult (*PLib3MFAttachment_WriteToBufferPtr) (Lib3MF_Attachment pA
*/
typedef Lib3MFResult (*PLib3MFAttachment_ReadFromBufferPtr) (Lib3MF_Attachment pAttachment, Lib3MF_uint64 nBufferBufferSize, const Lib3MF_uint8 * pBufferBuffer);

/**
* Retrieves an attachment's content type
*
* @param[in] pAttachment - Attachment instance.
* @param[in] nContentTypeBufferSize - size of the buffer (including trailing 0)
* @param[out] pContentTypeNeededChars - will be filled with the count of the written bytes, or needed buffer size.
* @param[out] pContentTypeBuffer - buffer of returns the attachment's content type string, may be NULL
* @return error code or 0 (success)
*/
typedef Lib3MFResult (*PLib3MFAttachment_GetContentTypePtr) (Lib3MF_Attachment pAttachment, const Lib3MF_uint32 nContentTypeBufferSize, Lib3MF_uint32* pContentTypeNeededChars, char * pContentTypeBuffer);

/*************************************************************************************************************************
Class definition for Texture2D
**************************************************************************************************************************/
Expand Down Expand Up @@ -6902,6 +6913,7 @@ typedef struct {
PLib3MFAttachment_GetStreamSizePtr m_Attachment_GetStreamSize;
PLib3MFAttachment_WriteToBufferPtr m_Attachment_WriteToBuffer;
PLib3MFAttachment_ReadFromBufferPtr m_Attachment_ReadFromBuffer;
PLib3MFAttachment_GetContentTypePtr m_Attachment_GetContentType;
PLib3MFTexture2D_GetAttachmentPtr m_Texture2D_GetAttachment;
PLib3MFTexture2D_SetAttachmentPtr m_Texture2D_SetAttachment;
PLib3MFTexture2D_GetContentTypePtr m_Texture2D_GetContentType;
Expand Down
31 changes: 29 additions & 2 deletions Autogenerated/Bindings/CppDynamic/lib3mf_dynamic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,7 @@ class CAttachment : public CBase {
inline Lib3MF_uint64 GetStreamSize();
inline void WriteToBuffer(std::vector<Lib3MF_uint8> & BufferBuffer);
inline void ReadFromBuffer(const CInputVector<Lib3MF_uint8> & BufferBuffer);
inline std::string GetContentType();
};

/*************************************************************************************************************************
Expand Down Expand Up @@ -4171,6 +4172,7 @@ inline CBase* CWrapper::polymorphicFactory(Lib3MFHandle pHandle)
pWrapperTable->m_Attachment_GetStreamSize = nullptr;
pWrapperTable->m_Attachment_WriteToBuffer = nullptr;
pWrapperTable->m_Attachment_ReadFromBuffer = nullptr;
pWrapperTable->m_Attachment_GetContentType = nullptr;
pWrapperTable->m_Texture2D_GetAttachment = nullptr;
pWrapperTable->m_Texture2D_SetAttachment = nullptr;
pWrapperTable->m_Texture2D_GetContentType = nullptr;
Expand Down Expand Up @@ -7073,6 +7075,15 @@ inline CBase* CWrapper::polymorphicFactory(Lib3MFHandle pHandle)
if (pWrapperTable->m_Attachment_ReadFromBuffer == nullptr)
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

#ifdef _WIN32
pWrapperTable->m_Attachment_GetContentType = (PLib3MFAttachment_GetContentTypePtr) GetProcAddress(hLibrary, "lib3mf_attachment_getcontenttype");
#else // _WIN32
pWrapperTable->m_Attachment_GetContentType = (PLib3MFAttachment_GetContentTypePtr) dlsym(hLibrary, "lib3mf_attachment_getcontenttype");
dlerror();
#endif // _WIN32
if (pWrapperTable->m_Attachment_GetContentType == nullptr)
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

#ifdef _WIN32
pWrapperTable->m_Texture2D_GetAttachment = (PLib3MFTexture2D_GetAttachmentPtr) GetProcAddress(hLibrary, "lib3mf_texture2d_getattachment");
#else // _WIN32
Expand Down Expand Up @@ -11274,6 +11285,10 @@ inline CBase* CWrapper::polymorphicFactory(Lib3MFHandle pHandle)
if ( (eLookupError != 0) || (pWrapperTable->m_Attachment_ReadFromBuffer == nullptr) )
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

eLookupError = (*pLookup)("lib3mf_attachment_getcontenttype", (void**)&(pWrapperTable->m_Attachment_GetContentType));
if ( (eLookupError != 0) || (pWrapperTable->m_Attachment_GetContentType == nullptr) )
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

eLookupError = (*pLookup)("lib3mf_texture2d_getattachment", (void**)&(pWrapperTable->m_Texture2D_GetAttachment));
if ( (eLookupError != 0) || (pWrapperTable->m_Texture2D_GetAttachment == nullptr) )
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;
Expand Down Expand Up @@ -16212,8 +16227,20 @@ inline CBase* CWrapper::polymorphicFactory(Lib3MFHandle pHandle)
}

/**
* Method definitions for class CTexture2D
*/
* CAttachment::GetContentType - Retrieves an attachment's content type
* @return returns the attachment's content type string
*/
std::string CAttachment::GetContentType()
{
Lib3MF_uint32 bytesNeededContentType = 0;
Lib3MF_uint32 bytesWrittenContentType = 0;
CheckError(m_pWrapper->m_WrapperTable.m_Attachment_GetContentType(m_pHandle, 0, &bytesNeededContentType, nullptr));
std::vector<char> bufferContentType(bytesNeededContentType);
CheckError(m_pWrapper->m_WrapperTable.m_Attachment_GetContentType(m_pHandle, bytesNeededContentType, &bytesWrittenContentType, &bufferContentType[0]));

return std::string(&bufferContentType[0]);
}


/**
* CTexture2D::GetAttachment - Retrieves the attachment located at the path of the texture.
Expand Down
11 changes: 11 additions & 0 deletions Autogenerated/Source/lib3mf_abi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2923,6 +2923,17 @@ LIB3MF_DECLSPEC Lib3MFResult lib3mf_attachment_writetobuffer(Lib3MF_Attachment p
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_attachment_readfrombuffer(Lib3MF_Attachment pAttachment, Lib3MF_uint64 nBufferBufferSize, const Lib3MF_uint8 * pBufferBuffer);

/**
* Retrieves an attachment's content type
*
* @param[in] pAttachment - Attachment instance.
* @param[in] nContentTypeBufferSize - size of the buffer (including trailing 0)
* @param[out] pContentTypeNeededChars - will be filled with the count of the written bytes, or needed buffer size.
* @param[out] pContentTypeBuffer - buffer of returns the attachment's content type string, may be NULL
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_attachment_getcontenttype(Lib3MF_Attachment pAttachment, const Lib3MF_uint32 nContentTypeBufferSize, Lib3MF_uint32* pContentTypeNeededChars, char * pContentTypeBuffer);

/*************************************************************************************************************************
Class definition for Texture2D
**************************************************************************************************************************/
Expand Down
6 changes: 6 additions & 0 deletions Autogenerated/Source/lib3mf_interfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3017,6 +3017,12 @@ class IAttachment : public virtual IBase {
*/
virtual void ReadFromBuffer(const Lib3MF_uint64 nBufferBufferSize, const Lib3MF_uint8 * pBufferBuffer) = 0;

/**
* IAttachment::GetContentType - Retrieves an attachment's content type
* @return returns the attachment's content type string
*/
virtual std::string GetContentType() = 0;

};

typedef IBaseSharedPtr<IAttachment> PIAttachment;
Expand Down
58 changes: 58 additions & 0 deletions Autogenerated/Source/lib3mf_interfacewrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10409,6 +10409,62 @@ Lib3MFResult lib3mf_attachment_readfrombuffer(Lib3MF_Attachment pAttachment, Lib
}
}

Lib3MFResult lib3mf_attachment_getcontenttype(Lib3MF_Attachment pAttachment, const Lib3MF_uint32 nContentTypeBufferSize, Lib3MF_uint32* pContentTypeNeededChars, char * pContentTypeBuffer)
{
IBase* pIBaseClass = (IBase *)pAttachment;

PLib3MFInterfaceJournalEntry pJournalEntry;
try {
if (m_GlobalJournal.get() != nullptr) {
pJournalEntry = m_GlobalJournal->beginClassMethod(pAttachment, "Attachment", "GetContentType");
}
if ( (!pContentTypeBuffer) && !(pContentTypeNeededChars) )
throw ELib3MFInterfaceException (LIB3MF_ERROR_INVALIDPARAM);
std::string sContentType("");
IAttachment* pIAttachment = dynamic_cast<IAttachment*>(pIBaseClass);
if (!pIAttachment)
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCAST);

bool isCacheCall = (pContentTypeBuffer == nullptr);
if (isCacheCall) {
sContentType = pIAttachment->GetContentType();

pIAttachment->_setCache (new ParameterCache_1<std::string> (sContentType));
}
else {
auto cache = dynamic_cast<ParameterCache_1<std::string>*> (pIAttachment->_getCache ());
if (cache == nullptr)
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCAST);
cache->retrieveData (sContentType);
pIAttachment->_setCache (nullptr);
}

if (pContentTypeNeededChars)
*pContentTypeNeededChars = (Lib3MF_uint32) (sContentType.size()+1);
if (pContentTypeBuffer) {
if (sContentType.size() >= nContentTypeBufferSize)
throw ELib3MFInterfaceException (LIB3MF_ERROR_BUFFERTOOSMALL);
for (size_t iContentType = 0; iContentType < sContentType.size(); iContentType++)
pContentTypeBuffer[iContentType] = sContentType[iContentType];
pContentTypeBuffer[sContentType.size()] = 0;
}
if (pJournalEntry.get() != nullptr) {
pJournalEntry->addStringResult("ContentType", sContentType.c_str());
pJournalEntry->writeSuccess();
}
return LIB3MF_SUCCESS;
}
catch (ELib3MFInterfaceException & Exception) {
return handleLib3MFException(pIBaseClass, Exception, pJournalEntry.get());
}
catch (std::exception & StdException) {
return handleStdException(pIBaseClass, StdException, pJournalEntry.get());
}
catch (...) {
return handleUnhandledException(pIBaseClass, pJournalEntry.get());
}
}


/*************************************************************************************************************************
Class implementation for Texture2D
Expand Down Expand Up @@ -23899,6 +23955,8 @@ Lib3MFResult Lib3MF::Impl::Lib3MF_GetProcAddress (const char * pProcName, void *
*ppProcAddress = (void*) &lib3mf_attachment_writetobuffer;
if (sProcName == "lib3mf_attachment_readfrombuffer")
*ppProcAddress = (void*) &lib3mf_attachment_readfrombuffer;
if (sProcName == "lib3mf_attachment_getcontenttype")
*ppProcAddress = (void*) &lib3mf_attachment_getcontenttype;
if (sProcName == "lib3mf_texture2d_getattachment")
*ppProcAddress = (void*) &lib3mf_texture2d_getattachment;
if (sProcName == "lib3mf_texture2d_setattachment")
Expand Down
2 changes: 2 additions & 0 deletions Include/API/lib3mf_attachment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class CAttachment : public virtual IAttachment, public virtual CBase {

void ReadFromBuffer(const Lib3MF_uint64 nBufferBufferSize, const Lib3MF_uint8 * pBufferBuffer);

std::string GetContentType();

NMR::PModelAttachment getModelAttachment ();

};
Expand Down
1 change: 1 addition & 0 deletions Include/Common/OPC/NMR_IOpcPackageReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace NMR {
virtual _Ret_maybenull_ COpcPackageRelationship * findRootRelation(_In_ std::string sRelationType, _In_ nfBool bMustBeUnique) = 0;
virtual POpcPackagePart createPart(_In_ std::string sPath) = 0;
virtual nfUint64 getPartSize(_In_ std::string sPath) = 0;
virtual std::string getContentType(_In_ std::string sPath) { return ""; }
virtual void close() {}
};

Expand Down
2 changes: 2 additions & 0 deletions Include/Common/OPC/NMR_OpcPackageReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace NMR {
std::string m_relationShipExtension;

std::map<std::string, std::string> m_ContentTypes;
std::map<std::string, std::string> m_ContentTypesByExtension;
std::list<POpcPackageRelationship> m_RootRelationships;

void releaseZIP();
Expand All @@ -80,6 +81,7 @@ namespace NMR {
_Ret_maybenull_ COpcPackageRelationship * findRootRelation(_In_ std::string sRelationType, _In_ nfBool bMustBeUnique) override;
POpcPackagePart createPart(_In_ std::string sPath) override;
nfUint64 getPartSize(_In_ std::string sPath) override;
std::string getContentType(_In_ std::string sPath) override;
};

typedef std::shared_ptr<COpcPackageReader> POpcPackageReader;
Expand Down
3 changes: 3 additions & 0 deletions Include/Model/Classes/NMR_ModelAttachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace NMR {
PImportStream m_pStream;
std::string m_sPathURI;
std::string m_sRelationShipType;
std::string m_sContentType;

public:
CModelAttachment() = delete;
Expand All @@ -59,10 +60,12 @@ namespace NMR {
_Ret_notnull_ CModel * getModel();
std::string getPathURI();
std::string getRelationShipType();
std::string getContentType();
PImportStream getStream ();

void setStream(_In_ PImportStream pStream);
void setRelationShipType(_In_ const std::string sRelationShipType);
void setContentType(_In_ const std::string sContentType);

PModelAttachment cloneIntoNewModel (_In_ CModel * pModel, _In_ nfBool bCloneMemory);
};
Expand Down
1 change: 1 addition & 0 deletions Include/Model/Reader/NMR_KeyStoreOpcPackageReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace NMR {
virtual COpcPackageRelationship * findRootRelation(std::string sRelationType, nfBool bMustBeUnique) override;
virtual POpcPackagePart createPart(std::string sPath) override;
virtual nfUint64 getPartSize(std::string sPath) override;
virtual std::string getContentType(std::string sPath) override;

void close() override;
};
Expand Down
5 changes: 5 additions & 0 deletions Source/API/lib3mf_attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,8 @@ NMR::PModelAttachment CAttachment::getModelAttachment()
{
return m_pModelAttachment;
}

std::string CAttachment::GetContentType()
{
return m_pModelAttachment->getContentType();
}
31 changes: 31 additions & 0 deletions Source/Common/OPC/NMR_OpcPackageReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ namespace NMR {
if (pContentType->m_contentType == PACKAGE_3D_MODEL_CONTENT_TYPE) {
modelExtension = pContentType->m_extension;
}
m_ContentTypesByExtension[pContentType->m_extension] = pContentType->m_contentType;
}
if (m_relationShipExtension.empty())
throw CNMRException(NMR_ERROR_OPC_MISSING_EXTENSION_FOR_RELATIONSHIP);
Expand All @@ -281,12 +282,42 @@ namespace NMR {
if (pOverrideContentType->m_contentType == PACKAGE_3D_MODEL_CONTENT_TYPE) {
modelPart = pOverrideContentType->m_partName;
}
m_ContentTypes[pOverrideContentType->m_partName] = pOverrideContentType->m_contentType;
}

if (modelExtension.empty() && modelPart.empty())
throw CNMRException(NMR_ERROR_OPC_MISSING_EXTENSION_FOR_MODEL);
}

std::string COpcPackageReader::getContentType(_In_ std::string sPath)
{
// Normalize path: remove leading slash
std::string sNormalizedPath = fnRemoveLeadingPathDelimiter(sPath);

// First check override entries by exact part name (with leading slash as stored in [Content_Types].xml)
auto iIterator = m_ContentTypes.find("/" + sNormalizedPath);
if (iIterator != m_ContentTypes.end()) {
return iIterator->second;
}
// Also check without leading slash
iIterator = m_ContentTypes.find(sNormalizedPath);
if (iIterator != m_ContentTypes.end()) {
return iIterator->second;
}

// Fall back to extension-based lookup
size_t nDotPos = sNormalizedPath.rfind('.');
if (nDotPos != std::string::npos) {
std::string sExtension = sNormalizedPath.substr(nDotPos + 1);
auto iExtIterator = m_ContentTypesByExtension.find(sExtension);
if (iExtIterator != m_ContentTypesByExtension.end()) {
return iExtIterator->second;
}
}

return "";
}

void COpcPackageReader::readRootRelationships()
{
PImportStream pRelStream = openZIPEntry(OPCPACKAGE_PATH_ROOTRELATIONSHIPS);
Expand Down
Loading