lib3mf :
- primo commit.
This commit is contained in:
@@ -0,0 +1,260 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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.
|
||||
|
||||
This file has been generated by the Automatic Component Toolkit (ACT) version 1.5.0.
|
||||
|
||||
Abstract: This is an autogenerated C++ implementation file in order to allow easy
|
||||
development of the 3MF Library. It needs to be generated only once.
|
||||
|
||||
Interface version: 2.2.0
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_abi.hpp"
|
||||
#include "lib3mf_interfaces.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
#include "lib3mf_model.hpp"
|
||||
|
||||
#include "NMR_Spec_Version.h"
|
||||
#include "Model/Classes/NMR_ModelConstants.h"
|
||||
#include "Common/3MF_ProgressMonitor.h"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
void CWrapper::GetLibraryVersion(Lib3MF_uint32 & nMajor, Lib3MF_uint32 & nMinor, Lib3MF_uint32 & nMicro)
|
||||
{
|
||||
nMajor = LIB3MF_VERSION_MAJOR;
|
||||
nMinor = LIB3MF_VERSION_MINOR;
|
||||
nMicro = LIB3MF_VERSION_MICRO;
|
||||
}
|
||||
|
||||
bool CWrapper::GetPrereleaseInformation(std::string & sPrereleaseInfo)
|
||||
{
|
||||
sPrereleaseInfo = LIB3MF_VERSION_PRERELEASEINFO;
|
||||
return !sPrereleaseInfo.empty();
|
||||
}
|
||||
|
||||
bool CWrapper::GetBuildInformation(std::string & sBuildInformation)
|
||||
{
|
||||
sBuildInformation = LIB3MF_VERSION_BUILDINFO;
|
||||
return !sBuildInformation.empty();
|
||||
}
|
||||
|
||||
|
||||
void CWrapper::GetSpecificationVersion (const std::string & sSpecificationURL, bool & bIsSupported, Lib3MF_uint32 & nMajor, Lib3MF_uint32 & nMinor, Lib3MF_uint32 & nMicro)
|
||||
{
|
||||
if (!sSpecificationURL.compare(std::string(XML_3MF_NAMESPACE_CORESPEC100))) {
|
||||
nMajor = NMR_SPECVERSION_MAJOR;
|
||||
nMinor = NMR_SPECVERSION_MINOR;
|
||||
nMicro = NMR_SPECVERSION_MICRO;
|
||||
bIsSupported = true;
|
||||
} else if (!sSpecificationURL.compare( std::string(XML_3MF_NAMESPACE_MATERIALSPEC) )) {
|
||||
nMajor = NMR_SPECVERSION_MATERIAL_MAJOR;
|
||||
nMinor = NMR_SPECVERSION_MATERIAL_MINOR;
|
||||
nMicro = NMR_SPECVERSION_MATERIAL_MICRO;
|
||||
bIsSupported = true;
|
||||
} else if (!sSpecificationURL.compare( std::string(XML_3MF_NAMESPACE_PRODUCTIONSPEC) )) {
|
||||
nMajor = NMR_SPECVERSION_PRODUCTION_MAJOR;
|
||||
nMinor = NMR_SPECVERSION_PRODUCTION_MINOR;
|
||||
nMicro = NMR_SPECVERSION_PRODUCTION_MICRO;
|
||||
bIsSupported = true;
|
||||
} else if (!sSpecificationURL.compare( std::string(XML_3MF_NAMESPACE_BEAMLATTICESPEC) )) {
|
||||
nMajor = NMR_SPECVERSION_BEAMLATTICE_MAJOR;
|
||||
nMinor = NMR_SPECVERSION_BEAMLATTICE_MINOR;
|
||||
nMicro = NMR_SPECVERSION_BEAMLATTICE_MICRO;
|
||||
bIsSupported = true;
|
||||
}
|
||||
else if (!sSpecificationURL.compare(std::string(XML_3MF_NAMESPACE_SLICESPEC))) {
|
||||
nMajor = NMR_SPECVERSION_SLICE_MAJOR;
|
||||
nMinor = NMR_SPECVERSION_SLICE_MINOR;
|
||||
nMicro = NMR_SPECVERSION_SLICE_MICRO;
|
||||
bIsSupported = true;
|
||||
}
|
||||
else if (!sSpecificationURL.compare(std::string(XML_3MF_NAMESPACE_SECURECONTENTSPEC))) {
|
||||
nMajor = NMR_SPECVERSION_SECURECONTENT_MAJOR;
|
||||
nMinor = NMR_SPECVERSION_SECURECONTENT_MINOR;
|
||||
nMicro = NMR_SPECVERSION_SECURECONTENT_MICRO;
|
||||
bIsSupported = true;
|
||||
}
|
||||
else {
|
||||
bIsSupported = false;
|
||||
}
|
||||
}
|
||||
|
||||
IModel * CWrapper::CreateModel ()
|
||||
{
|
||||
return new CModel();
|
||||
}
|
||||
|
||||
void CWrapper::Release (IBase* pInstance)
|
||||
{
|
||||
IBase::ReleaseBaseClassInterface(pInstance);
|
||||
}
|
||||
|
||||
void CWrapper::Acquire(IBase* pInstance)
|
||||
{
|
||||
IBase::AcquireBaseClassInterface(pInstance);
|
||||
}
|
||||
|
||||
NMR::ProgressIdentifier convertProgressIdentifier(const eLib3MFProgressIdentifier progressIdentifier) {
|
||||
return NMR::ProgressIdentifier(progressIdentifier);
|
||||
//switch (progressIdentifier) {
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierQUERYCANCELED: return NMR::PROGRESS_QUERYCANCELED;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierDONE: return NMR::PROGRESS_DONE;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierCLEANUP: return NMR::PROGRESS_CLEANUP;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierREADSTREAM: return NMR::PROGRESS_READSTREAM;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierEXTRACTOPCPACKAGE: return NMR::PROGRESS_EXTRACTOPCPACKAGE;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierREADNONROOTMODELS: return NMR::PROGRESS_READNONROOTMODELS;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierREADROOTMODEL: return NMR::PROGRESS_READROOTMODEL;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierREADRESOURCES: return NMR::PROGRESS_READRESOURCES;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierREADMESH: return NMR::PROGRESS_READMESH;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierREADSLICES: return NMR::PROGRESS_READSLICES;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierREADBUILD: return NMR::PROGRESS_READBUILD;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierCREATEOPCPACKAGE: return NMR::PROGRESS_CREATEOPCPACKAGE;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierWRITEMODELSTOSTREAM: return NMR::PROGRESS_WRITEMODELSTOSTREAM;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierWRITEROOTMODEL: return NMR::PROGRESS_WRITEROOTMODEL;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierWRITENONROOTMODELS: return NMR::PROGRESS_WRITENONROOTMODELS;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierWRITEATTACHMENTS: return NMR::PROGRESS_WRITEATTACHMENTS;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierWRITECONTENTTYPES: return NMR::PROGRESS_WRITECONTENTTYPES;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierWRITENOBJECTS: return NMR::PROGRESS_WRITENOBJECTS;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierWRITENODES: return NMR::PROGRESS_WRITENODES;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierWRITETRIANGLES: return NMR::PROGRESS_WRITETRIANGLES;
|
||||
// case eLib3MFProgressIdentifier::eProgressIdentifierWRITESLICES: return NMR::PROGRESS_WRITESLICES;
|
||||
// default: throw ELib3MFInterfaceException(LIB3MF_ERROR_UNKOWNPROGRESSIDENTIFIER);
|
||||
//}
|
||||
}
|
||||
|
||||
bool CWrapper::GetLastError (IBase* pInstance, std::string & sLastErrorString)
|
||||
{
|
||||
if (pInstance != nullptr)
|
||||
return pInstance->GetLastErrorMessage(sLastErrorString);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CWrapper::RetrieveProgressMessage (const eLib3MFProgressIdentifier eProrgessIdentifier, std::string & sProgressMessage)
|
||||
{
|
||||
NMR::CProgressMonitor::GetProgressMessage(convertProgressIdentifier(eProrgessIdentifier), sProgressMessage);
|
||||
}
|
||||
|
||||
sLib3MFColor CWrapper::RGBAToColor (const Lib3MF_uint8 nRed, const Lib3MF_uint8 nGreen, const Lib3MF_uint8 nBlue, const Lib3MF_uint8 nAlpha)
|
||||
{
|
||||
sLib3MFColor s;
|
||||
s.m_Red = nRed;
|
||||
s.m_Green = nGreen;
|
||||
s.m_Blue = nBlue;
|
||||
s.m_Alpha = nAlpha;
|
||||
return s;
|
||||
}
|
||||
|
||||
sLib3MFColor CWrapper::FloatRGBAToColor (const Lib3MF_single fRed, const Lib3MF_single fGreen, const Lib3MF_single fBlue, const Lib3MF_single fAlpha)
|
||||
{
|
||||
sLib3MFColor s;
|
||||
s.m_Red = (Lib3MF_uint8)std::round(std::max(std::min(fRed, 1.f), 0.f) * 255.0f);
|
||||
s.m_Green = (Lib3MF_uint8)std::round(std::max(std::min(fGreen, 1.f), 0.f) * 255.0f);
|
||||
s.m_Blue = (Lib3MF_uint8)std::round(std::max(std::min(fBlue, 1.f), 0.f) * 255.0f);
|
||||
s.m_Alpha = (Lib3MF_uint8)std::round(std::max(std::min(fAlpha, 1.f), 0.f) * 255.0f);
|
||||
return s;
|
||||
}
|
||||
|
||||
void CWrapper::ColorToRGBA (const sLib3MFColor TheColor, Lib3MF_uint8 & nRed, Lib3MF_uint8 & nGreen, Lib3MF_uint8 & nBlue, Lib3MF_uint8 & nAlpha)
|
||||
{
|
||||
nRed = TheColor.m_Red;
|
||||
nGreen = TheColor.m_Green;
|
||||
nBlue = TheColor.m_Blue;
|
||||
nAlpha = TheColor.m_Alpha;
|
||||
}
|
||||
|
||||
void CWrapper::ColorToFloatRGBA (const sLib3MFColor TheColor, Lib3MF_single & fRed, Lib3MF_single & fGreen, Lib3MF_single & fBlue, Lib3MF_single & fAlpha)
|
||||
{
|
||||
fRed = TheColor.m_Red / 255.f;
|
||||
fGreen = TheColor.m_Green / 255.f;
|
||||
fBlue = TheColor.m_Blue / 255.f;
|
||||
fAlpha = TheColor.m_Alpha / 255.f;
|
||||
}
|
||||
|
||||
sLib3MFTransform CWrapper::GetIdentityTransform ()
|
||||
{
|
||||
int i, j;
|
||||
sLib3MFTransform Transform;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
for (j = 0; j < 3; j++)
|
||||
Transform.m_Fields[i][j] = (i == j) ? 1.0f : 0.0f;
|
||||
|
||||
return Transform;
|
||||
|
||||
}
|
||||
|
||||
sLib3MFTransform CWrapper::GetUniformScaleTransform (const Lib3MF_single fFactor)
|
||||
{
|
||||
int i, j;
|
||||
sLib3MFTransform Transform;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
for (j = 0; j < 3; j++)
|
||||
Transform.m_Fields[i][j] = (i == j) ? fFactor : 0.0f;
|
||||
|
||||
return Transform;
|
||||
}
|
||||
|
||||
sLib3MFTransform CWrapper::GetScaleTransform (const Lib3MF_single fFactorX, const Lib3MF_single fFactorY, const Lib3MF_single fFactorZ)
|
||||
{
|
||||
int i, j;
|
||||
sLib3MFTransform Transform;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
for (j = 0; j < 3; j++)
|
||||
Transform.m_Fields[i][j] = (i == j) ? 1.0f : 0.0f;
|
||||
|
||||
Transform.m_Fields[0][0] = fFactorX;
|
||||
Transform.m_Fields[1][1] = fFactorY;
|
||||
Transform.m_Fields[2][2] = fFactorZ;
|
||||
|
||||
return Transform;
|
||||
|
||||
}
|
||||
|
||||
sLib3MFTransform CWrapper::GetTranslationTransform(const Lib3MF_single fVectorX, const Lib3MF_single fVectorY, const Lib3MF_single fVectorZ)
|
||||
{
|
||||
int i, j;
|
||||
sLib3MFTransform Transform;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 3; j++)
|
||||
Transform.m_Fields[i][j] = (i == j) ? 1.0f : 0.0f;
|
||||
|
||||
Transform.m_Fields[3][0] = fVectorX;
|
||||
Transform.m_Fields[3][1] = fVectorY;
|
||||
Transform.m_Fields[3][2] = fVectorZ;
|
||||
|
||||
return Transform;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "lib3mf_accessright.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
#include "lib3mf_consumer.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
Lib3MF::Impl::CAccessRight::CAccessRight(NMR::PKeyStoreAccessRight ar) {
|
||||
m_pAccessRight = ar;
|
||||
}
|
||||
|
||||
IConsumer * Lib3MF::Impl::CAccessRight::GetConsumer() {
|
||||
return new CConsumer(m_pAccessRight->getConsumer());
|
||||
}
|
||||
|
||||
Lib3MF::eWrappingAlgorithm Lib3MF::Impl::CAccessRight::GetWrappingAlgorithm() {
|
||||
NMR::eKeyStoreWrapAlgorithm ea = m_pAccessRight->getAlgorithm();
|
||||
return static_cast<Lib3MF::eWrappingAlgorithm>(ea);
|
||||
}
|
||||
|
||||
Lib3MF::eMgfAlgorithm Lib3MF::Impl::CAccessRight::GetMgfAlgorithm() {
|
||||
NMR::eKeyStoreMaskGenerationFunction mgf = m_pAccessRight->getMgf();
|
||||
return static_cast<Lib3MF::eMgfAlgorithm>(mgf);
|
||||
}
|
||||
|
||||
Lib3MF::eDigestMethod Lib3MF::Impl::CAccessRight::GetDigestMethod() {
|
||||
NMR::eKeyStoreMessageDigest digest = m_pAccessRight->getDigest();
|
||||
return static_cast<Lib3MF::eDigestMethod>(digest);
|
||||
}
|
||||
|
||||
NMR::PKeyStoreAccessRight Lib3MF::Impl::CAccessRight::accessRight() const {
|
||||
return m_pAccessRight;
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CAttachment
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_attachment.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "Common/Platform/NMR_ImportStream_Unique_Memory.h"
|
||||
#include "Common/Platform/NMR_ImportStream_Callback.h"
|
||||
#include "Common/Platform/NMR_ImportStream.h"
|
||||
#include "Common/Platform/NMR_Platform.h"
|
||||
#include "Common/NMR_StringUtils.h"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CAttachment
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CAttachment::CAttachment(NMR::PModelAttachment pModelAttachment)
|
||||
: m_pModelAttachment(pModelAttachment)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string CAttachment::GetPath ()
|
||||
{
|
||||
return m_pModelAttachment->getPathURI();
|
||||
}
|
||||
|
||||
void CAttachment::SetPath (const std::string & sPath)
|
||||
{
|
||||
NMR::CModel * pModel = m_pModelAttachment->getModel();
|
||||
NMR::PImportStream pStream = m_pModelAttachment->getStream();
|
||||
if (pModel->getPackageThumbnail() == m_pModelAttachment) {
|
||||
// different handling for package-wide attachment
|
||||
pModel->removePackageThumbnail();
|
||||
m_pModelAttachment = pModel->addPackageThumbnail(sPath, pStream);
|
||||
}
|
||||
else {
|
||||
std::string sRelationshipType = m_pModelAttachment->getRelationShipType();
|
||||
pModel->removeAttachment(m_pModelAttachment->getPathURI());
|
||||
m_pModelAttachment = pModel->addAttachment(sPath, sRelationshipType, pStream);
|
||||
}
|
||||
}
|
||||
|
||||
IPackagePart * CAttachment::PackagePart()
|
||||
{
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_NOTIMPLEMENTED);
|
||||
}
|
||||
|
||||
std::string CAttachment::GetRelationShipType ()
|
||||
{
|
||||
return m_pModelAttachment->getRelationShipType();
|
||||
}
|
||||
|
||||
void CAttachment::SetRelationShipType (const std::string & sPath)
|
||||
{
|
||||
m_pModelAttachment->setRelationShipType(sPath);
|
||||
}
|
||||
|
||||
void CAttachment::WriteToFile (const std::string & sFileName)
|
||||
{
|
||||
NMR::PImportStream pStream = m_pModelAttachment->getStream();
|
||||
|
||||
if (pStream.get() != nullptr) {
|
||||
pStream->writeToFile(NMR::fnUTF8toUTF16(sFileName).c_str());
|
||||
} else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDATTACHMENTSTREAM);
|
||||
}
|
||||
}
|
||||
|
||||
void CAttachment::ReadFromFile (const std::string & sFileName)
|
||||
{
|
||||
NMR::PImportStream pImportStream = NMR::fnCreateImportStreamInstance(sFileName.c_str());
|
||||
|
||||
m_pModelAttachment->setStream(pImportStream);
|
||||
}
|
||||
|
||||
void CAttachment::ReadFromCallback(const Lib3MF::ReadCallback pTheReadCallback, const Lib3MF_uint64 nStreamSize, const Lib3MF::SeekCallback pTheSeekCallback, const Lib3MF_pvoid pUserData)
|
||||
{
|
||||
NMR::ImportStream_ReadCallbackType lambdaReadCallback =
|
||||
[pTheReadCallback](NMR::nfByte* pData, NMR::nfUint64 cbBytes, void* pUserData)
|
||||
{
|
||||
(*pTheReadCallback)(reinterpret_cast<Lib3MF_uint64>(pData), cbBytes, pUserData);
|
||||
return 0;
|
||||
};
|
||||
|
||||
NMR::ImportStream_SeekCallbackType lambdaSeekCallback =
|
||||
[pTheSeekCallback](NMR::nfUint64 nPosition, void* pUserData)
|
||||
{
|
||||
(*pTheSeekCallback)(nPosition, pUserData);
|
||||
return 0;
|
||||
};
|
||||
|
||||
NMR::PImportStream pImportStream = std::make_shared<NMR::CImportStream_Callback>(
|
||||
lambdaReadCallback, lambdaSeekCallback,
|
||||
pUserData, nStreamSize);
|
||||
try {
|
||||
m_pModelAttachment->setStream(pImportStream);
|
||||
}
|
||||
catch (NMR::CNMRException& e) {
|
||||
if (e.getErrorCode() == NMR_USERABORTED) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
}
|
||||
else throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Lib3MF_uint64 CAttachment::GetStreamSize ()
|
||||
{
|
||||
NMR::PImportStream pStream = m_pModelAttachment->getStream();
|
||||
return pStream->retrieveSize();
|
||||
}
|
||||
|
||||
void CAttachment::WriteToBuffer (Lib3MF_uint64 nBufferBufferSize, Lib3MF_uint64* pBufferNeededCount, Lib3MF_uint8 * pBufferBuffer)
|
||||
{
|
||||
NMR::PImportStream pStream = m_pModelAttachment->getStream();
|
||||
|
||||
Lib3MF_uint64 cbStreamSize = pStream->retrieveSize();
|
||||
if (pBufferNeededCount)
|
||||
*pBufferNeededCount = cbStreamSize;
|
||||
|
||||
if (nBufferBufferSize >= cbStreamSize) {
|
||||
pStream->seekPosition(0, true);
|
||||
pStream->readIntoBuffer(pBufferBuffer, cbStreamSize, true);
|
||||
}
|
||||
}
|
||||
|
||||
void CAttachment::ReadFromBuffer(const Lib3MF_uint64 nBufferBufferSize, const Lib3MF_uint8 * pBufferBuffer)
|
||||
{
|
||||
NMR::PImportStream pImportStream = std::make_shared<NMR::CImportStream_Unique_Memory>(pBufferBuffer, nBufferBufferSize);
|
||||
m_pModelAttachment->setStream(pImportStream);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CBase
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_base.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CBase
|
||||
**************************************************************************************************************************/
|
||||
|
||||
bool CBase::GetLastErrorMessage(std::string & sErrorMessage)
|
||||
{
|
||||
if (m_pErrors && !m_pErrors->empty()) {
|
||||
sErrorMessage = m_pErrors->back();
|
||||
return true;
|
||||
} else {
|
||||
sErrorMessage = "";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void CBase::ClearErrorMessages()
|
||||
{
|
||||
m_pErrors.reset();
|
||||
}
|
||||
|
||||
void CBase::RegisterErrorMessage(const std::string & sErrorMessage)
|
||||
{
|
||||
if (!m_pErrors) {
|
||||
m_pErrors.reset(new std::list<std::string>());
|
||||
}
|
||||
m_pErrors->clear();
|
||||
m_pErrors->push_back(sErrorMessage);
|
||||
}
|
||||
|
||||
void CBase::IncRefCount()
|
||||
{
|
||||
++m_nReferenceCount;
|
||||
}
|
||||
|
||||
bool CBase::DecRefCount()
|
||||
{
|
||||
m_nReferenceCount--;
|
||||
if (!m_nReferenceCount) {
|
||||
delete this;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CBaseMaterialGroup
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_basematerialgroup.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CBaseMaterialGroup
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CBaseMaterialGroup::CBaseMaterialGroup(NMR::PModelBaseMaterialResource pResource)
|
||||
: CResource(std::static_pointer_cast<NMR::CModelResource>(pResource))
|
||||
{
|
||||
}
|
||||
|
||||
NMR::CModelBaseMaterialResource& CBaseMaterialGroup::baseMaterialGroup()
|
||||
{
|
||||
NMR::CModelBaseMaterialResource* pBaseMaterialGroup = dynamic_cast<NMR::CModelBaseMaterialResource*>(resource().get());
|
||||
if (pBaseMaterialGroup == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDBASEMATERIALGROUP);
|
||||
return *pBaseMaterialGroup;
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CBaseMaterialGroup::GetCount ()
|
||||
{
|
||||
return baseMaterialGroup().getCount();
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CBaseMaterialGroup::AddMaterial(const std::string & sName, const sLib3MFColor DisplayColor)
|
||||
{
|
||||
NMR::nfColor cColor = DisplayColor.m_Red | (DisplayColor.m_Green << 8) | (DisplayColor.m_Blue << 16) | (DisplayColor.m_Alpha << 24);
|
||||
|
||||
return baseMaterialGroup().addBaseMaterial(sName, cColor);
|
||||
}
|
||||
|
||||
void CBaseMaterialGroup::RemoveMaterial (const Lib3MF_uint32 nPropertyID)
|
||||
{
|
||||
baseMaterialGroup().removeMaterial(nPropertyID);
|
||||
}
|
||||
|
||||
std::string CBaseMaterialGroup::GetName (const Lib3MF_uint32 nPropertyID)
|
||||
{
|
||||
return baseMaterialGroup().getBaseMaterial(nPropertyID)->getName();
|
||||
}
|
||||
|
||||
void CBaseMaterialGroup::SetName (const Lib3MF_uint32 nPropertyID, const std::string & sName)
|
||||
{
|
||||
baseMaterialGroup().getBaseMaterial(nPropertyID)->setName(sName);
|
||||
}
|
||||
|
||||
void CBaseMaterialGroup::SetDisplayColor(const Lib3MF_uint32 nPropertyID, const sLib3MFColor TheColor)
|
||||
{
|
||||
NMR::nfColor cColor = TheColor.m_Red | (TheColor.m_Green << 8) | (TheColor.m_Blue << 16) | (TheColor.m_Alpha << 24);
|
||||
baseMaterialGroup().getBaseMaterial(nPropertyID)->setColor(cColor);
|
||||
}
|
||||
|
||||
sLib3MFColor CBaseMaterialGroup::GetDisplayColor(const Lib3MF_uint32 nPropertyID)
|
||||
{
|
||||
NMR::nfColor cColor = baseMaterialGroup().getBaseMaterial(nPropertyID)->getDisplayColor();
|
||||
sLib3MFColor c;
|
||||
c.m_Red = (cColor) & 0xff;
|
||||
c.m_Green = (cColor >> 8) & 0xff;
|
||||
c.m_Blue = (cColor >> 16) & 0xff;
|
||||
c.m_Alpha = (cColor >> 24) & 0xff;
|
||||
return c;
|
||||
}
|
||||
|
||||
void CBaseMaterialGroup::GetAllPropertyIDs(Lib3MF_uint64 nPropertyIDsBufferSize, Lib3MF_uint64* pPropertyIDsNeededCount, Lib3MF_uint32 * pPropertyIDsBuffer)
|
||||
{
|
||||
Lib3MF_uint32 nMaterialCount = baseMaterialGroup().getCount();
|
||||
|
||||
if (pPropertyIDsNeededCount)
|
||||
*pPropertyIDsNeededCount = nMaterialCount;
|
||||
|
||||
if (nPropertyIDsBufferSize >= nMaterialCount && pPropertyIDsBuffer) {
|
||||
if (!baseMaterialGroup().hasResourceIndexMap()) {
|
||||
baseMaterialGroup().buildResourceIndexMap();
|
||||
}
|
||||
for (Lib3MF_uint32 i = 0; i < nMaterialCount; i++) {
|
||||
DWORD nPropertyID;
|
||||
if (baseMaterialGroup().mapResourceIndexToPropertyID(i, nPropertyID)) {
|
||||
*pPropertyIDsBuffer = nPropertyID;
|
||||
}
|
||||
else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDRESOURCEINDEX);
|
||||
}
|
||||
pPropertyIDsBuffer++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CBaseMaterialGroupIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_basematerialgroupiterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
#include "lib3mf_basematerialgroup.hpp"
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CBaseMaterialGroupIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
IBaseMaterialGroup * CBaseMaterialGroupIterator::GetCurrentBaseMaterialGroup()
|
||||
{
|
||||
// Create specific API class
|
||||
return new CBaseMaterialGroup(std::dynamic_pointer_cast<NMR::CModelBaseMaterialResource>(GetCurrentResource()));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,486 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CBeamLattice
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_beamlattice.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
#include "lib3mf_beamset.hpp"
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CBeamLattice
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CBeamLattice::CBeamLattice(NMR::PModelMeshObject pMeshObject, NMR::PModelMeshBeamLatticeAttributes pAttributes):
|
||||
m_mesh(*pMeshObject->getMesh()), m_pAttributes(pAttributes), m_pMeshObject(pMeshObject)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Lib3MF_double CBeamLattice::GetMinLength ()
|
||||
{
|
||||
return m_mesh.getBeamLatticeMinLength();
|
||||
}
|
||||
|
||||
void CBeamLattice::SetMinLength (const Lib3MF_double dMinLength)
|
||||
{
|
||||
return m_mesh.setBeamLatticeMinLength(dMinLength);
|
||||
}
|
||||
|
||||
void CBeamLattice::GetClipping(eLib3MFBeamLatticeClipMode & eClipMode, Lib3MF_uint32 & nUniqueResourceID)
|
||||
{
|
||||
if (!m_pAttributes->m_bHasClippingMeshID) {
|
||||
eClipMode = eBeamLatticeClipMode::NoClipMode;
|
||||
nUniqueResourceID = 0;
|
||||
}
|
||||
else {
|
||||
eClipMode = eBeamLatticeClipMode(m_pAttributes->m_eClipMode);
|
||||
nUniqueResourceID = m_pAttributes->m_pClippingMeshUniqueID->getUniqueID();
|
||||
}
|
||||
}
|
||||
|
||||
void CBeamLattice::SetClipping(const eLib3MFBeamLatticeClipMode eClipMode, const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
if ( ((int)eClipMode == (NMR::eModelBeamLatticeClipMode::MODELBEAMLATTICECLIPMODE_NONE)) || (nUniqueResourceID == 0) ){
|
||||
m_pAttributes->m_eClipMode = NMR::eModelBeamLatticeClipMode(eClipMode);
|
||||
m_pAttributes->m_bHasClippingMeshID = false;
|
||||
m_pAttributes->m_pClippingMeshUniqueID = nullptr;
|
||||
}
|
||||
else {
|
||||
NMR::CModel* pModel = m_pMeshObject->getModel();
|
||||
|
||||
NMR::CModelMeshObject * pClippingObject = dynamic_cast<NMR::CModelMeshObject*>(pModel->findObject(nUniqueResourceID));
|
||||
if (pClippingObject == nullptr) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
// check, if this object will be written before
|
||||
NMR::nfInt32 nComp = pModel->compareObjectsByResourceID(pClippingObject, m_pMeshObject.get());
|
||||
if (nComp < 0) { // pClippingObject has been defined after m_pMeshObject
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
|
||||
m_pAttributes->m_eClipMode = NMR::eModelBeamLatticeClipMode(eClipMode);;
|
||||
m_pAttributes->m_bHasClippingMeshID = true;
|
||||
m_pAttributes->m_pClippingMeshUniqueID = pClippingObject->getPackageResourceID();
|
||||
}
|
||||
}
|
||||
|
||||
bool CBeamLattice::GetRepresentation (Lib3MF_uint32 & nUniqueResourceID)
|
||||
{
|
||||
if (m_pAttributes->m_bHasRepresentationMeshID) {
|
||||
nUniqueResourceID = m_pAttributes->m_pRepresentationUniqueID->getUniqueID();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
nUniqueResourceID = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void CBeamLattice::SetRepresentation (const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
if (nUniqueResourceID == 0) {
|
||||
m_pAttributes->m_bHasRepresentationMeshID = false;
|
||||
m_pAttributes->m_pRepresentationUniqueID = nullptr;
|
||||
}
|
||||
else {
|
||||
NMR::CModel* pModel = m_pMeshObject->getModel();
|
||||
|
||||
NMR::CModelMeshObject * pRepresentationObject = dynamic_cast<NMR::CModelMeshObject*>(pModel->findObject(nUniqueResourceID));
|
||||
if (pRepresentationObject == nullptr) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
// check, if this object will be written before
|
||||
NMR::nfInt32 nComp = pModel->compareObjectsByResourceID(pRepresentationObject, m_pMeshObject.get());
|
||||
if (nComp < 0) { // pClippingObject has been defined after m_pMeshObject
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
|
||||
m_pAttributes->m_bHasRepresentationMeshID = true;
|
||||
m_pAttributes->m_pRepresentationUniqueID = pRepresentationObject->getPackageResourceID();
|
||||
}
|
||||
}
|
||||
|
||||
void CBeamLattice::GetBallOptions (eLib3MFBeamLatticeBallMode & eBallMode, Lib3MF_double & dBallRadius)
|
||||
{
|
||||
eBallMode = (eLib3MFBeamLatticeBallMode)m_mesh.getBeamLatticeBallMode();
|
||||
dBallRadius = m_mesh.getDefaultBallRadius();
|
||||
}
|
||||
|
||||
void CBeamLattice::SetBallOptions (const eLib3MFBeamLatticeBallMode eBallMode, const Lib3MF_double dBallRadius)
|
||||
{
|
||||
if (eBallMode == eLib3MFBeamLatticeBallMode::None || dBallRadius > 0.0) {
|
||||
m_mesh.setBeamLatticeBallMode((NMR::eModelBeamLatticeBallMode)eBallMode);
|
||||
m_mesh.setDefaultBallRadius(dBallRadius);
|
||||
}
|
||||
else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CBeamLattice::GetBeamCount ()
|
||||
{
|
||||
return m_mesh.getBeamCount();
|
||||
}
|
||||
|
||||
sLib3MFBeam CBeamLattice::GetBeam (const Lib3MF_uint32 nIndex)
|
||||
{
|
||||
sLib3MFBeam beam;
|
||||
NMR::MESHBEAM* meshBeam = m_mesh.getBeam(nIndex);
|
||||
beam.m_CapModes[0] = (eLib3MFBeamLatticeCapMode)(meshBeam->m_capMode[0]);
|
||||
beam.m_CapModes[1] = (eLib3MFBeamLatticeCapMode)meshBeam->m_capMode[1];
|
||||
|
||||
beam.m_Indices[0] = meshBeam->m_nodeindices[0];
|
||||
beam.m_Indices[1] = meshBeam->m_nodeindices[1];
|
||||
|
||||
beam.m_Radii[0] = meshBeam->m_radius[0];
|
||||
beam.m_Radii[1] = meshBeam->m_radius[1];
|
||||
return beam;
|
||||
}
|
||||
|
||||
bool isBeamValid(const Lib3MF_uint32 nNodeCount, const sLib3MFBeam& BeamInfo)
|
||||
{
|
||||
for (int j = 0; j < 2; j++) {
|
||||
if (BeamInfo.m_Indices[j] >= nNodeCount)
|
||||
return false;
|
||||
if (BeamInfo.m_Radii[j] <= 0)
|
||||
return false;
|
||||
}
|
||||
if (BeamInfo.m_Indices[0] == BeamInfo.m_Indices[1])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CBeamLattice::AddBeam (const sLib3MFBeam BeamInfo)
|
||||
{
|
||||
if (!m_pMeshObject->isValidForBeamLattices())
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_BEAMLATTICE_INVALID_OBJECTTYPE);
|
||||
|
||||
// Check for input validity
|
||||
if (!isBeamValid(m_mesh.getNodeCount(), BeamInfo))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
// retrieve nodes and add beam
|
||||
NMR::MESHNODE * pNodes[2];
|
||||
for (int j = 0; j < 2; j++)
|
||||
pNodes[j] = m_mesh.getNode(BeamInfo.m_Indices[j]);
|
||||
|
||||
NMR::MESHBEAM * pMeshBeam = m_mesh.addBeam(pNodes[0], pNodes[1], BeamInfo.m_Radii[0], BeamInfo.m_Radii[1], (int)BeamInfo.m_CapModes[0], (int)BeamInfo.m_CapModes[1]);
|
||||
return pMeshBeam->m_index;
|
||||
}
|
||||
|
||||
void CBeamLattice::SetBeam (const Lib3MF_uint32 nIndex, const sLib3MFBeam BeamInfo)
|
||||
{
|
||||
if (!isBeamValid(m_mesh.getNodeCount(), BeamInfo))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
NMR::MESHBEAM* meshBeam = m_mesh.getBeam(nIndex);
|
||||
meshBeam->m_capMode[0] = (int)BeamInfo.m_CapModes[0];
|
||||
meshBeam->m_capMode[1] = (int)BeamInfo.m_CapModes[1];
|
||||
|
||||
meshBeam->m_nodeindices[0] = BeamInfo.m_Indices[0];
|
||||
meshBeam->m_nodeindices[1] = BeamInfo.m_Indices[1];
|
||||
|
||||
meshBeam->m_radius[0] = BeamInfo.m_Radii[0];
|
||||
meshBeam->m_radius[1] = BeamInfo.m_Radii[1];
|
||||
|
||||
// Occupied nodes may have changed, need to validate
|
||||
m_mesh.scanOccupiedNodes();
|
||||
m_mesh.validateBeamLatticeBalls();
|
||||
}
|
||||
|
||||
void CBeamLattice::SetBeams(const Lib3MF_uint64 nBeamInfoBufferSize, const sLib3MFBeam * pBeamInfoBuffer)
|
||||
{
|
||||
if ((nBeamInfoBufferSize>0) && (!m_pMeshObject->isValidForBeamLattices()))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_BEAMLATTICE_INVALID_OBJECTTYPE);
|
||||
|
||||
m_mesh.clearBeamLatticeBeams();
|
||||
|
||||
const sLib3MFBeam* pBeamInfoCurrent = pBeamInfoBuffer;
|
||||
for (Lib3MF_uint32 nIndex = 0; nIndex < nBeamInfoBufferSize; nIndex++)
|
||||
{
|
||||
if (!isBeamValid(m_mesh.getNodeCount(), *pBeamInfoCurrent))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
NMR::MESHNODE * pNodes[2];
|
||||
for (int j = 0; j < 2; j++)
|
||||
pNodes[j] = m_mesh.getNode(pBeamInfoCurrent->m_Indices[j]);
|
||||
|
||||
m_mesh.addBeam(pNodes[0], pNodes[1], pBeamInfoCurrent->m_Radii[0], pBeamInfoCurrent->m_Radii[1], (int)pBeamInfoCurrent->m_CapModes[0], (int)pBeamInfoCurrent->m_CapModes[1]);
|
||||
pBeamInfoCurrent++;
|
||||
}
|
||||
|
||||
// Occupied nodes may have changed, need to validate
|
||||
m_mesh.validateBeamLatticeBalls();
|
||||
}
|
||||
|
||||
void CBeamLattice::GetBeams(Lib3MF_uint64 nBeamInfoBufferSize, Lib3MF_uint64* pBeamInfoNeededCount, sLib3MFBeam * pBeamInfoBuffer)
|
||||
{
|
||||
Lib3MF_uint32 beamCount = m_mesh.getBeamCount();
|
||||
if (pBeamInfoNeededCount)
|
||||
*pBeamInfoNeededCount = beamCount;
|
||||
|
||||
if (nBeamInfoBufferSize >= beamCount && pBeamInfoBuffer)
|
||||
{
|
||||
sLib3MFBeam* beam = pBeamInfoBuffer;
|
||||
for (Lib3MF_uint32 i = 0; i < beamCount; i++)
|
||||
{
|
||||
const NMR::MESHBEAM* meshBeam = m_mesh.getBeam(i);
|
||||
beam->m_CapModes[0] = (eLib3MFBeamLatticeCapMode)meshBeam->m_capMode[0];
|
||||
beam->m_CapModes[1] = (eLib3MFBeamLatticeCapMode)meshBeam->m_capMode[1];
|
||||
|
||||
beam->m_Indices[0] = meshBeam->m_nodeindices[0];
|
||||
beam->m_Indices[1] = meshBeam->m_nodeindices[1];
|
||||
|
||||
beam->m_Radii[0] = meshBeam->m_radius[0];
|
||||
beam->m_Radii[1] = meshBeam->m_radius[1];
|
||||
beam++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CBeamLattice::GetBallCount ()
|
||||
{
|
||||
eBeamLatticeBallMode ballMode = (eBeamLatticeBallMode)m_mesh.getBeamLatticeBallMode();
|
||||
|
||||
if (ballMode == eBeamLatticeBallMode::Mixed) {
|
||||
return m_mesh.getBallCount();
|
||||
}
|
||||
else if (ballMode == eBeamLatticeBallMode::All) {
|
||||
return m_mesh.getOccupiedNodeCount();
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
sLib3MFBall CBeamLattice::GetBall (const Lib3MF_uint32 nIndex)
|
||||
{
|
||||
sLib3MFBall ball;
|
||||
|
||||
eBeamLatticeBallMode ballMode;
|
||||
Lib3MF_double defaultBallRadius;
|
||||
GetBallOptions(ballMode, defaultBallRadius);
|
||||
|
||||
Lib3MF_uint32 ballCount = GetBallCount();
|
||||
if (nIndex >= ballCount) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDRESOURCEINDEX);
|
||||
}
|
||||
|
||||
if (ballMode == eBeamLatticeBallMode::Mixed) {
|
||||
NMR::MESHBALL * meshBall = m_mesh.getBall(nIndex);
|
||||
|
||||
ball.m_Index = meshBall->m_nodeindex;
|
||||
|
||||
ball.m_Radius = meshBall->m_radius;
|
||||
|
||||
return ball;
|
||||
}
|
||||
else if (ballMode == eBeamLatticeBallMode::All) {
|
||||
Lib3MF_uint32 ballNodeIndex = m_mesh.getOccupiedNode(nIndex)->m_index;
|
||||
|
||||
Lib3MF_uint32 meshBallCount = m_mesh.getBallCount();
|
||||
for (Lib3MF_uint32 iBall = 0; iBall < meshBallCount; iBall++) {
|
||||
NMR::MESHBALL * meshBall = m_mesh.getBall(iBall);
|
||||
|
||||
if (meshBall->m_nodeindex == ballNodeIndex) {
|
||||
ball.m_Index = meshBall->m_nodeindex;
|
||||
|
||||
ball.m_Radius = meshBall->m_radius;
|
||||
|
||||
return ball;
|
||||
}
|
||||
}
|
||||
|
||||
ball.m_Index = ballNodeIndex;
|
||||
|
||||
ball.m_Radius = defaultBallRadius;
|
||||
|
||||
return ball;
|
||||
}
|
||||
else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
}
|
||||
|
||||
bool isBallValid(const Lib3MF_uint32 nNodeCount, const sLib3MFBall& BallInfo)
|
||||
{
|
||||
if (BallInfo.m_Index >= nNodeCount)
|
||||
return false;
|
||||
if (BallInfo.m_Radius <= 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CBeamLattice::AddBall (const sLib3MFBall BallInfo)
|
||||
{
|
||||
if (!m_pMeshObject->isValidForBeamLattices())
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_BEAMLATTICE_INVALID_OBJECTTYPE);
|
||||
|
||||
// Check for input validity
|
||||
if (!isBallValid(m_mesh.getNodeCount(), BallInfo))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
// retrieve node and add ball
|
||||
NMR::MESHNODE * pNode = m_mesh.getNode(BallInfo.m_Index);
|
||||
|
||||
NMR::MESHBALL * pMeshBall = m_mesh.addBall(pNode, BallInfo.m_Radius);
|
||||
return pMeshBall->m_index;
|
||||
}
|
||||
|
||||
void CBeamLattice::SetBall (const Lib3MF_uint32 nIndex, const sLib3MFBall BallInfo)
|
||||
{
|
||||
if (!isBallValid(m_mesh.getNodeCount(), BallInfo))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
if (!m_mesh.isNodeOccupied(BallInfo.m_Index)) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
|
||||
eBeamLatticeBallMode ballMode = (eBeamLatticeBallMode(m_mesh.getBeamLatticeBallMode()));
|
||||
|
||||
if (ballMode == eBeamLatticeBallMode::Mixed) {
|
||||
NMR::MESHBALL * meshBall = m_mesh.getBall(nIndex);
|
||||
|
||||
meshBall->m_nodeindex = BallInfo.m_Index;
|
||||
|
||||
meshBall->m_radius = BallInfo.m_Radius;
|
||||
}
|
||||
else if (ballMode == eBeamLatticeBallMode::All) {
|
||||
Lib3MF_uint32 ballNodeIndex = m_mesh.getOccupiedNode(nIndex)->m_index;
|
||||
Lib3MF_uint32 meshBallCount = m_mesh.getBallCount();
|
||||
for (Lib3MF_uint32 iBall = 0; iBall < meshBallCount; iBall++) {
|
||||
NMR::MESHBALL * meshBall = m_mesh.getBall(iBall);
|
||||
|
||||
if (meshBall->m_nodeindex == ballNodeIndex) {
|
||||
meshBall->m_nodeindex = BallInfo.m_Index;
|
||||
meshBall->m_radius = BallInfo.m_Radius;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Not in mesh, add the ball
|
||||
NMR::MESHNODE * pNode = m_mesh.getNode(BallInfo.m_Index);
|
||||
|
||||
m_mesh.addBall(pNode, BallInfo.m_Radius);
|
||||
}
|
||||
else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
}
|
||||
|
||||
void CBeamLattice::SetBalls (const Lib3MF_uint64 nBallInfoBufferSize, const sLib3MFBall * pBallInfoBuffer)
|
||||
{
|
||||
if ((nBallInfoBufferSize > 0) && (!m_pMeshObject->isValidForBeamLattices()))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_BEAMLATTICE_INVALID_OBJECTTYPE);
|
||||
|
||||
m_mesh.clearBeamLatticeBalls();
|
||||
|
||||
const sLib3MFBall * pBallInfoCurrent = pBallInfoBuffer;
|
||||
for (Lib3MF_uint32 nIndex = 0; nIndex < nBallInfoBufferSize; nIndex++)
|
||||
{
|
||||
if (!isBallValid(m_mesh.getNodeCount(), *pBallInfoCurrent))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
NMR::MESHNODE * pNode = m_mesh.getNode(pBallInfoCurrent->m_Index);
|
||||
|
||||
m_mesh.addBall(pNode, pBallInfoCurrent->m_Radius);
|
||||
pBallInfoCurrent++;
|
||||
}
|
||||
}
|
||||
|
||||
void CBeamLattice::GetBalls(Lib3MF_uint64 nBallInfoBufferSize, Lib3MF_uint64 * pBallInfoNeededCount, sLib3MFBall * pBallInfoBuffer)
|
||||
{
|
||||
Lib3MF_uint32 ballCount = GetBallCount();
|
||||
if (pBallInfoNeededCount)
|
||||
*pBallInfoNeededCount = ballCount;
|
||||
|
||||
if (nBallInfoBufferSize >= ballCount && pBallInfoBuffer) {
|
||||
eBeamLatticeBallMode ballMode;
|
||||
Lib3MF_double defaultBallRadius;
|
||||
GetBallOptions(ballMode, defaultBallRadius);
|
||||
|
||||
if (ballMode == eBeamLatticeBallMode::Mixed) {
|
||||
sLib3MFBall * ball = pBallInfoBuffer;
|
||||
for (Lib3MF_uint32 iBall = 0; iBall < ballCount; iBall++) {
|
||||
const NMR::MESHBALL * meshBall = m_mesh.getBall(iBall);
|
||||
|
||||
ball->m_Index = meshBall->m_nodeindex;
|
||||
|
||||
ball->m_Radius = meshBall->m_radius;
|
||||
ball++;
|
||||
}
|
||||
}
|
||||
else if (ballMode == eBeamLatticeBallMode::All) {
|
||||
Lib3MF_uint32 meshBallCount = m_mesh.getBallCount();
|
||||
|
||||
// Sort balls that are in the mesh into a map by node index
|
||||
std::map<Lib3MF_uint32, Lib3MF_double> meshBallMap;
|
||||
for (Lib3MF_uint32 iBall = 0; iBall < meshBallCount; iBall++) {
|
||||
const NMR::MESHBALL * meshBall = m_mesh.getBall(iBall);
|
||||
|
||||
meshBallMap[meshBall->m_nodeindex] = meshBall->m_radius;
|
||||
}
|
||||
|
||||
// Fill balls from default or mesh balls
|
||||
sLib3MFBall * ball = pBallInfoBuffer;
|
||||
for (Lib3MF_uint32 i = 0; i < ballCount; i++) {
|
||||
Lib3MF_uint32 currNodeIndex = m_mesh.getOccupiedNode(i)->m_index;
|
||||
|
||||
ball->m_Index = currNodeIndex;
|
||||
ball->m_Radius = meshBallMap[currNodeIndex] > 0.0 ? meshBallMap[currNodeIndex] : defaultBallRadius;
|
||||
|
||||
ball++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CBeamLattice::GetBeamSetCount ()
|
||||
{
|
||||
return m_mesh.getBeamSetCount();
|
||||
}
|
||||
|
||||
IBeamSet * CBeamLattice::AddBeamSet ()
|
||||
{
|
||||
return new CBeamSet(m_mesh.addBeamSet(), m_pMeshObject);
|
||||
}
|
||||
|
||||
IBeamSet * CBeamLattice::GetBeamSet (const Lib3MF_uint32 nIndex)
|
||||
{
|
||||
return new CBeamSet(m_mesh.getBeamSet(nIndex), m_pMeshObject);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CBeamSet
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_beamset.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CBeamSet
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CBeamSet::CBeamSet(NMR::PBEAMSET pBeamSet, NMR::PModelMeshObject pMeshObject):
|
||||
m_pBeamSet(pBeamSet), m_mesh(*pMeshObject->getMesh())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CBeamSet::SetName(const std::string & sName)
|
||||
{
|
||||
m_pBeamSet->m_sName = sName;
|
||||
}
|
||||
|
||||
std::string CBeamSet::GetName()
|
||||
{
|
||||
return m_pBeamSet->m_sName;
|
||||
}
|
||||
|
||||
void CBeamSet::SetIdentifier(const std::string & sIdentifier)
|
||||
{
|
||||
// Ensure identifier is unique
|
||||
if (sIdentifier.compare("") != 0) {
|
||||
Lib3MF_uint32 nBeamSets = m_mesh.getBeamSetCount();
|
||||
for (Lib3MF_uint32 iBeamSet = 0; iBeamSet < nBeamSets; iBeamSet++)
|
||||
if (sIdentifier.compare(m_mesh.getBeamSet(iBeamSet)->m_sIdentifier) == 0)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
|
||||
m_pBeamSet->m_sIdentifier = sIdentifier;
|
||||
}
|
||||
|
||||
std::string CBeamSet::GetIdentifier()
|
||||
{
|
||||
return m_pBeamSet->m_sIdentifier;
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CBeamSet::GetReferenceCount()
|
||||
{
|
||||
return (Lib3MF_uint32)m_pBeamSet->m_Refs.size();
|
||||
}
|
||||
|
||||
void CBeamSet::SetReferences(const Lib3MF_uint64 nReferencesBufferSize, const Lib3MF_uint32 * pReferencesBuffer)
|
||||
{
|
||||
if (nReferencesBufferSize > LIB3MF_MAXBEAMCOUNT)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ELEMENTCOUNTEXCEEDSLIMIT);
|
||||
|
||||
m_pBeamSet->m_Refs.resize((size_t) nReferencesBufferSize);
|
||||
const Lib3MF_uint32 beamCount = m_mesh.getBeamCount();
|
||||
for (size_t i = 0; i < (size_t)nReferencesBufferSize; i++) {
|
||||
if (beamCount <= pReferencesBuffer[i])
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
m_pBeamSet->m_Refs[i] = Lib3MF_uint32(pReferencesBuffer[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CBeamSet::GetReferences(Lib3MF_uint64 nReferencesBufferSize, Lib3MF_uint64* pReferencesNeededCount, Lib3MF_uint32 * pReferencesBuffer)
|
||||
{
|
||||
Lib3MF_uint32 referenceCount = (Lib3MF_uint32)m_pBeamSet->m_Refs.size();
|
||||
if (pReferencesNeededCount)
|
||||
*pReferencesNeededCount = referenceCount;
|
||||
|
||||
if (nReferencesBufferSize >= referenceCount && pReferencesBuffer)
|
||||
{
|
||||
Lib3MF_uint32* pRef = pReferencesBuffer;
|
||||
for (Lib3MF_uint32 i = 0; i < referenceCount; i++)
|
||||
{
|
||||
*pRef = m_pBeamSet->m_Refs[i];
|
||||
pRef++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CBeamSet::GetBallReferenceCount()
|
||||
{
|
||||
return (Lib3MF_uint32)m_pBeamSet->m_BallRefs.size();
|
||||
}
|
||||
|
||||
void CBeamSet::SetBallReferences(const Lib3MF_uint64 nBallReferencesBufferSize, const Lib3MF_uint32* pBallReferencesBuffer)
|
||||
{
|
||||
if (nBallReferencesBufferSize > LIB3MF_MAXBEAMCOUNT)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ELEMENTCOUNTEXCEEDSLIMIT);
|
||||
|
||||
m_pBeamSet->m_BallRefs.resize((size_t)nBallReferencesBufferSize);
|
||||
const Lib3MF_uint32 ballCount = m_mesh.getBallCount();
|
||||
for (size_t i = 0; i < (size_t)nBallReferencesBufferSize; i++) {
|
||||
if (ballCount <= pBallReferencesBuffer[i])
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
m_pBeamSet->m_BallRefs[i] = Lib3MF_uint32(pBallReferencesBuffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void CBeamSet::GetBallReferences(Lib3MF_uint64 nBallReferencesBufferSize, Lib3MF_uint64* pBallReferencesNeededCount, Lib3MF_uint32* pBallReferencesBuffer)
|
||||
{
|
||||
Lib3MF_uint32 ballReferenceCount = GetBallReferenceCount();
|
||||
if (pBallReferencesNeededCount)
|
||||
*pBallReferencesNeededCount = ballReferenceCount;
|
||||
|
||||
if (nBallReferencesBufferSize >= ballReferenceCount && pBallReferencesBuffer) {
|
||||
Lib3MF_uint32* pBallRef = pBallReferencesBuffer;
|
||||
for (Lib3MF_uint32 i = 0; i < ballReferenceCount; i++) {
|
||||
*pBallRef = m_pBeamSet->m_BallRefs[i];
|
||||
pBallRef++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CBuildItem
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_builditem.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
#include "lib3mf_utils.hpp"
|
||||
#include "lib3mf_object.hpp"
|
||||
#include "lib3mf_metadatagroup.hpp"
|
||||
// Include custom headers here.
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CBuildItem
|
||||
**************************************************************************************************************************/
|
||||
|
||||
NMR::CModelBuildItem& CBuildItem::buildItem()
|
||||
{
|
||||
return *m_pBuildItem.get();
|
||||
}
|
||||
|
||||
CBuildItem::CBuildItem(NMR::PModelBuildItem pBuildItem)
|
||||
{
|
||||
m_pBuildItem = pBuildItem;
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CBuildItem::GetHandle()
|
||||
{
|
||||
return buildItem().getHandle();
|
||||
}
|
||||
|
||||
IObject * CBuildItem::GetObjectResource ()
|
||||
{
|
||||
NMR::PModelResource pResource = buildItem().getModel()->findResource(buildItem().getObject()->getPackageResourceID());
|
||||
if (!pResource.get())
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDMODELRESOURCE);
|
||||
|
||||
std::unique_ptr<IObject> pResourceInterface(CObject::fnCreateObjectFromModelResource(pResource, true));
|
||||
if (pResourceInterface == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_RESOURCENOTFOUND);
|
||||
|
||||
return pResourceInterface.release();
|
||||
}
|
||||
|
||||
std::string CBuildItem::GetUUID (bool & bHasUUID)
|
||||
{
|
||||
bHasUUID = buildItem().uuid() != nullptr;
|
||||
if (bHasUUID)
|
||||
return buildItem().uuid()->toString();
|
||||
return "";
|
||||
}
|
||||
|
||||
void CBuildItem::SetUUID (const std::string & sUUID)
|
||||
{
|
||||
NMR::PUUID pUUID = std::make_shared<NMR::CUUID>(sUUID);
|
||||
buildItem().setUUID(pUUID);
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CBuildItem::GetObjectResourceID()
|
||||
{
|
||||
return buildItem().getObject()->getPackageResourceID()->getUniqueID();
|
||||
}
|
||||
|
||||
bool CBuildItem::HasObjectTransform ()
|
||||
{
|
||||
return buildItem().hasTransform();
|
||||
}
|
||||
|
||||
sLib3MFTransform CBuildItem::GetObjectTransform ()
|
||||
{
|
||||
const NMR::NMATRIX3 matrix = buildItem().getTransform();
|
||||
return MatrixToTransform(matrix);
|
||||
}
|
||||
|
||||
void CBuildItem::SetObjectTransform (const sLib3MFTransform Transform)
|
||||
{
|
||||
buildItem().setTransform(TransformToMatrix(Transform));
|
||||
}
|
||||
|
||||
std::string CBuildItem::GetPartNumber ()
|
||||
{
|
||||
return buildItem().getPartNumber();
|
||||
}
|
||||
|
||||
void CBuildItem::SetPartNumber (const std::string & sSetPartnumber)
|
||||
{
|
||||
buildItem().setPartNumber(sSetPartnumber);
|
||||
}
|
||||
|
||||
IMetaDataGroup * CBuildItem::GetMetaDataGroup ()
|
||||
{
|
||||
return new CMetaDataGroup(buildItem().metaDataGroup());
|
||||
}
|
||||
|
||||
Lib3MF::sBox CBuildItem::GetOutbox()
|
||||
{
|
||||
NMR::NOUTBOX3 sOutbox;
|
||||
NMR::fnOutboxInitialize(sOutbox);
|
||||
|
||||
buildItem().getObject()->extendOutbox(sOutbox, buildItem().getTransform());
|
||||
|
||||
sBox s;
|
||||
s.m_MinCoordinate[0] = sOutbox.m_min.m_fields[0];
|
||||
s.m_MinCoordinate[1] = sOutbox.m_min.m_fields[1];
|
||||
s.m_MinCoordinate[2] = sOutbox.m_min.m_fields[2];
|
||||
|
||||
s.m_MaxCoordinate[0] = sOutbox.m_max.m_fields[0];
|
||||
s.m_MaxCoordinate[1] = sOutbox.m_max.m_fields[1];
|
||||
s.m_MaxCoordinate[2] = sOutbox.m_max.m_fields[2];
|
||||
return s;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CBuildItemIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_builditemiterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
#include "lib3mf_builditem.hpp"
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CBuildItemIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CBuildItemIterator::CBuildItemIterator()
|
||||
{
|
||||
m_nCurrentIndex = -1;
|
||||
}
|
||||
|
||||
|
||||
void CBuildItemIterator::addBuildItem(NMR::PModelBuildItem pBuildItem)
|
||||
{
|
||||
m_pBuildItems.push_back(pBuildItem);
|
||||
}
|
||||
|
||||
bool CBuildItemIterator::MoveNext ()
|
||||
{
|
||||
// Get Resource Count
|
||||
Lib3MF_int32 nBuildItemCount = (Lib3MF_int32)m_pBuildItems.size();
|
||||
m_nCurrentIndex++;
|
||||
|
||||
// Check new Index
|
||||
if (m_nCurrentIndex >= nBuildItemCount) {
|
||||
m_nCurrentIndex = nBuildItemCount;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool CBuildItemIterator::MovePrevious ()
|
||||
{
|
||||
// Get Resource Count
|
||||
m_nCurrentIndex--;
|
||||
|
||||
// Check new Index
|
||||
if (m_nCurrentIndex <= -1) {
|
||||
m_nCurrentIndex = -1;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
IBuildItem * CBuildItemIterator::GetCurrent ()
|
||||
{
|
||||
// Get Resource Count
|
||||
Lib3MF_int32 nBuildItemCount = (Lib3MF_int32)m_pBuildItems.size();
|
||||
if ((m_nCurrentIndex < 0) || (m_nCurrentIndex >= nBuildItemCount))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ITERATORINVALIDINDEX);
|
||||
|
||||
// Create specific API class
|
||||
NMR::PModelBuildItem pBuildItem = m_pBuildItems[m_nCurrentIndex];
|
||||
|
||||
return new CBuildItem(pBuildItem);
|
||||
}
|
||||
|
||||
IBuildItemIterator * CBuildItemIterator::Clone ()
|
||||
{
|
||||
auto pBuildItems = std::unique_ptr<CBuildItemIterator>(new CBuildItemIterator());
|
||||
|
||||
for (auto iIterator = m_pBuildItems.begin(); iIterator != m_pBuildItems.end(); iIterator++)
|
||||
pBuildItems->addBuildItem(*iIterator);
|
||||
|
||||
return pBuildItems.release();
|
||||
}
|
||||
|
||||
Lib3MF_uint64 CBuildItemIterator::Count()
|
||||
{
|
||||
return m_pBuildItems.size();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CColorGroup
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_colorgroup.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CColorGroup
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CColorGroup::CColorGroup(NMR::PModelColorGroupResource pResource)
|
||||
: CResource(std::static_pointer_cast<NMR::CModelResource>(pResource))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
NMR::CModelColorGroupResource& CColorGroup::colorGroup()
|
||||
{
|
||||
NMR::CModelColorGroupResource* pColorGroup = dynamic_cast<NMR::CModelColorGroupResource*>(resource().get());
|
||||
if (pColorGroup == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCOLORGROUP);
|
||||
return *pColorGroup;
|
||||
}
|
||||
|
||||
|
||||
Lib3MF_uint32 CColorGroup::GetCount ()
|
||||
{
|
||||
return colorGroup().getCount();
|
||||
}
|
||||
|
||||
void CColorGroup::GetAllPropertyIDs (Lib3MF_uint64 nPropertyIDsBufferSize, Lib3MF_uint64* pPropertyIDsNeededCount, Lib3MF_uint32 * pPropertyIDsBuffer)
|
||||
{
|
||||
Lib3MF_uint32 nCount = colorGroup().getCount();
|
||||
|
||||
if (pPropertyIDsNeededCount)
|
||||
*pPropertyIDsNeededCount = nCount;
|
||||
|
||||
if (nPropertyIDsBufferSize >= nCount && pPropertyIDsBuffer) {
|
||||
if (!colorGroup().hasResourceIndexMap()) {
|
||||
colorGroup().buildResourceIndexMap();
|
||||
}
|
||||
for (Lib3MF_uint32 i = 0; i < nCount; i++) {
|
||||
DWORD nPropertyID;
|
||||
if (colorGroup().mapResourceIndexToPropertyID(i, nPropertyID)) {
|
||||
*pPropertyIDsBuffer = nPropertyID;
|
||||
}
|
||||
else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDRESOURCEINDEX);
|
||||
}
|
||||
pPropertyIDsBuffer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CColorGroup::AddColor (const sLib3MFColor TheColor)
|
||||
{
|
||||
NMR::nfColor cColor = TheColor.m_Red | (TheColor.m_Green << 8) | (TheColor.m_Blue << 16) | (TheColor.m_Alpha << 24);
|
||||
|
||||
return colorGroup().addColor(cColor);
|
||||
}
|
||||
|
||||
void CColorGroup::SetColor (const Lib3MF_uint32 nPropertyID, const sLib3MFColor TheColor)
|
||||
{
|
||||
NMR::nfColor cColor = TheColor.m_Red | (TheColor.m_Green << 8) | (TheColor.m_Blue << 16) | (TheColor.m_Alpha << 24);
|
||||
colorGroup().setColor(nPropertyID, cColor);
|
||||
}
|
||||
|
||||
sLib3MFColor CColorGroup::GetColor (const Lib3MF_uint32 nPropertyID)
|
||||
{
|
||||
NMR::nfColor cColor = colorGroup().getColor(nPropertyID);
|
||||
sLib3MFColor c;
|
||||
c.m_Red = (cColor) & 0xff;
|
||||
c.m_Green = (cColor >> 8) & 0xff;
|
||||
c.m_Blue = (cColor >> 16) & 0xff;
|
||||
c.m_Alpha = (cColor >> 24) & 0xff;
|
||||
return c;
|
||||
}
|
||||
|
||||
void CColorGroup::RemoveColor(const Lib3MF_uint32 nPropertyID)
|
||||
{
|
||||
colorGroup().removeColor(nPropertyID);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CColorGroupIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_colorgroupiterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_colorgroup.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CColorGroupIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
IColorGroup * CColorGroupIterator::GetCurrentColorGroup ()
|
||||
{
|
||||
// Create specific API class
|
||||
return new CColorGroup(std::dynamic_pointer_cast<NMR::CModelColorGroupResource>(GetCurrentResource()));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CComponent
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_component.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_utils.hpp"
|
||||
#include "lib3mf_object.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CComponent
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CComponent::CComponent(NMR::PModelComponent pComponent)
|
||||
{
|
||||
if (pComponent.get() == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCOMPONENT);
|
||||
m_pComponent = pComponent;
|
||||
}
|
||||
|
||||
|
||||
IObject * CComponent::GetObjectResource()
|
||||
{
|
||||
NMR::PModelResource pModelObject = m_pComponent->getModel()->findResource(m_pComponent->getObject()->getPackageResourceID());
|
||||
if (!pModelObject.get())
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDMODELRESOURCE);
|
||||
|
||||
std::unique_ptr<IObject> pObject(CObject::fnCreateObjectFromModelResource(pModelObject, true));
|
||||
if (pObject == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_RESOURCENOTFOUND);
|
||||
|
||||
return pObject.release();
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CComponent::GetObjectResourceID()
|
||||
{
|
||||
return m_pComponent->getObject()->getPackageResourceID()->getUniqueID();
|
||||
}
|
||||
|
||||
std::string CComponent::GetUUID(bool & bHasUUID)
|
||||
{
|
||||
NMR::PUUID pUUID = m_pComponent->uuid();
|
||||
bHasUUID = (pUUID.get() != nullptr);
|
||||
if (bHasUUID)
|
||||
return pUUID->toString();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
void CComponent::SetUUID(const std::string & sUUID)
|
||||
{
|
||||
NMR::PUUID pUUID = std::make_shared<NMR::CUUID>(sUUID);
|
||||
m_pComponent->setUUID(pUUID);
|
||||
}
|
||||
|
||||
bool CComponent::HasTransform()
|
||||
{
|
||||
return m_pComponent->hasTransform();
|
||||
}
|
||||
|
||||
void CComponent::SetTransform (const sLib3MFTransform Transform)
|
||||
{
|
||||
m_pComponent->setTransform(TransformToMatrix(Transform));
|
||||
}
|
||||
|
||||
sLib3MFTransform CComponent::GetTransform()
|
||||
{
|
||||
const NMR::NMATRIX3 matrix = m_pComponent->getTransform();
|
||||
return MatrixToTransform(matrix);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CComponentsObject
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_componentsobject.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
#include "lib3mf_component.hpp"
|
||||
#include "lib3mf_utils.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CComponentsObject
|
||||
**************************************************************************************************************************/
|
||||
|
||||
|
||||
IComponentsObject* CComponentsObject::fnCreateComponentsObjectFromModelResource(NMR::PModelResource pResource, bool bFailIfUnkownClass)
|
||||
{
|
||||
|
||||
if (!pResource.get())
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
NMR::CModelComponentsObject * pMeshObject = dynamic_cast<NMR::CModelComponentsObject *> (pResource.get());
|
||||
if (pMeshObject) {
|
||||
return new CComponentsObject(pResource);
|
||||
}
|
||||
|
||||
if (bFailIfUnkownClass)
|
||||
throw ELib3MFInterfaceException(NMR_ERROR_UNKNOWNMODELRESOURCE);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CComponentsObject::CComponentsObject(NMR::PModelResource pResource)
|
||||
: CResource(pResource), CObject(pResource)
|
||||
{
|
||||
}
|
||||
|
||||
NMR::CModelComponentsObject * CComponentsObject::getComponentsObject()
|
||||
{
|
||||
NMR::CModelComponentsObject * pComponentsObject = dynamic_cast<NMR::CModelComponentsObject *> (resource().get());
|
||||
if (pComponentsObject == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCOMPONENTSOBJECT);
|
||||
|
||||
return pComponentsObject;
|
||||
}
|
||||
|
||||
IComponent * CComponentsObject::AddComponent(IObject* pObjectResource, const sLib3MFTransform Transform)
|
||||
{
|
||||
NMR::CModelComponentsObject * pComponentsObject = getComponentsObject();
|
||||
NMR::CModel * pModel = pComponentsObject->getModel();
|
||||
if (pModel == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDMODEL);
|
||||
|
||||
// Get Resource ID
|
||||
NMR::UniqueResourceID nObjectID = pObjectResource->GetResourceID();
|
||||
|
||||
if (GetResourceID() == nObjectID)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_FORBIDDENCYCLICREFERENCE);
|
||||
|
||||
// TODO: check all ancestors to avoid circular references
|
||||
|
||||
// Find class instance
|
||||
NMR::CModelObject * pObject = pModel->findObject(nObjectID);
|
||||
if (pObject == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_RESOURCENOTFOUND);
|
||||
|
||||
// Convert Transform, if given
|
||||
NMR::NMATRIX3 mMatrix = TransformToMatrix(Transform);
|
||||
|
||||
// Create Model component
|
||||
NMR::PModelComponent pNewComponent = std::make_shared<NMR::CModelComponent>(pObject, mMatrix);
|
||||
pComponentsObject->addComponent(pNewComponent);
|
||||
|
||||
return new CComponent(pNewComponent);
|
||||
}
|
||||
|
||||
IComponent * CComponentsObject::GetComponent (const Lib3MF_uint32 nIndex)
|
||||
{
|
||||
NMR::CModelComponentsObject * pComponentsObject = getComponentsObject();
|
||||
NMR::PModelComponent pNewComponent = pComponentsObject->getComponent(nIndex);
|
||||
return new CComponent(pNewComponent);
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CComponentsObject::GetComponentCount ()
|
||||
{
|
||||
return getComponentsObject()->getComponentCount();
|
||||
}
|
||||
|
||||
bool CComponentsObject::IsMeshObject()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CComponentsObject::IsComponentsObject()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CComponentsObjectIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_componentsobjectiterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_componentsobject.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CComponentsObjectIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
IComponentsObject * CComponentsObjectIterator::GetCurrentComponentsObject ()
|
||||
{
|
||||
return CComponentsObject::fnCreateComponentsObjectFromModelResource(GetCurrentResource(), true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CCompositeMaterials
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_compositematerials.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_basematerialgroup.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CCompositeMaterials
|
||||
**************************************************************************************************************************/
|
||||
|
||||
|
||||
CCompositeMaterials::CCompositeMaterials(NMR::PModelCompositeMaterialsResource pResource)
|
||||
: CResource(std::static_pointer_cast<NMR::CModelResource>(pResource))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
NMR::CModelCompositeMaterialsResource& CCompositeMaterials::compositeMaterials()
|
||||
{
|
||||
NMR::CModelCompositeMaterialsResource* pCompositeMaterials = dynamic_cast<NMR::CModelCompositeMaterialsResource*>(resource().get());
|
||||
if (pCompositeMaterials == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCOMPOSITEMATERIALS);
|
||||
return *pCompositeMaterials;
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CCompositeMaterials::GetCount ()
|
||||
{
|
||||
return compositeMaterials().getCount();
|
||||
}
|
||||
|
||||
void CCompositeMaterials::GetAllPropertyIDs (Lib3MF_uint64 nPropertyIDsBufferSize, Lib3MF_uint64* pPropertyIDsNeededCount, Lib3MF_uint32 * pPropertyIDsBuffer)
|
||||
{
|
||||
Lib3MF_uint32 nCompositesCount = compositeMaterials().getCount();
|
||||
|
||||
if (pPropertyIDsNeededCount)
|
||||
*pPropertyIDsNeededCount = nCompositesCount;
|
||||
|
||||
if (nPropertyIDsBufferSize >= nCompositesCount && pPropertyIDsBuffer) {
|
||||
if (!compositeMaterials().hasResourceIndexMap()) {
|
||||
compositeMaterials().buildResourceIndexMap();
|
||||
}
|
||||
for (Lib3MF_uint32 i = 0; i < nCompositesCount; i++) {
|
||||
DWORD nPropertyID;
|
||||
if (compositeMaterials().mapResourceIndexToPropertyID(i, nPropertyID)) {
|
||||
*pPropertyIDsBuffer = nPropertyID;
|
||||
}
|
||||
else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDRESOURCEINDEX);
|
||||
}
|
||||
pPropertyIDsBuffer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IBaseMaterialGroup * CCompositeMaterials::GetBaseMaterialGroup ()
|
||||
{
|
||||
return new CBaseMaterialGroup(compositeMaterials().getBaseMaterialResource());
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CCompositeMaterials::AddComposite(const Lib3MF_uint64 nCompositeBufferSize, const sLib3MFCompositeConstituent * pCompositeBuffer)
|
||||
{
|
||||
if (nCompositeBufferSize > LIB3MF_MAXCOMPOSITEMATERIALS)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ELEMENTCOUNTEXCEEDSLIMIT);
|
||||
|
||||
NMR::PModelComposite constituents = std::make_shared<NMR::CModelComposite>();
|
||||
constituents->resize((size_t)nCompositeBufferSize);
|
||||
for (size_t i = 0; i < (size_t)nCompositeBufferSize; i++) {
|
||||
(*constituents)[i].m_dMixingRatio = pCompositeBuffer[i].m_MixingRatio;
|
||||
(*constituents)[i].m_nPropertyID = pCompositeBuffer[i].m_PropertyID;
|
||||
}
|
||||
return compositeMaterials().addComposite(constituents);
|
||||
}
|
||||
|
||||
void CCompositeMaterials::RemoveComposite (const Lib3MF_uint32 nPropertyID)
|
||||
{
|
||||
compositeMaterials().removeComposite(nPropertyID);
|
||||
}
|
||||
|
||||
void CCompositeMaterials::GetComposite(const Lib3MF_uint32 nPropertyID, Lib3MF_uint64 nCompositeBufferSize, Lib3MF_uint64* pCompositeNeededCount, sLib3MFCompositeConstituent * pCompositeBuffer)
|
||||
{
|
||||
|
||||
if (nCompositeBufferSize > LIB3MF_MAXCOMPOSITEMATERIALS)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ELEMENTCOUNTEXCEEDSLIMIT);
|
||||
|
||||
NMR::PModelComposite constituents = compositeMaterials().getComposite(nPropertyID);
|
||||
|
||||
if (pCompositeNeededCount) {
|
||||
*pCompositeNeededCount = constituents->size();
|
||||
}
|
||||
|
||||
if (pCompositeBuffer && nCompositeBufferSize >= constituents->size()) {
|
||||
for (size_t i = 0; i < (size_t) nCompositeBufferSize; i++) {
|
||||
pCompositeBuffer[i].m_MixingRatio = (*constituents)[i].m_dMixingRatio;
|
||||
pCompositeBuffer[i].m_PropertyID = (*constituents)[i].m_nPropertyID;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CCompositeMaterialsIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_compositematerialsiterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_compositematerials.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CCompositeMaterialsIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
ICompositeMaterials * CCompositeMaterialsIterator::GetCurrentCompositeMaterials ()
|
||||
{
|
||||
// Create specific API class
|
||||
return new CCompositeMaterials(std::dynamic_pointer_cast<NMR::CModelCompositeMaterialsResource>(GetCurrentResource()));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "lib3mf_consumer.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
#include "Model/Classes/NMR_KeyStoreConsumer.h"
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
Lib3MF::Impl::CConsumer::CConsumer(NMR::PKeyStoreConsumer const & consumer) {
|
||||
m_Consumer = consumer;
|
||||
}
|
||||
|
||||
std::string Lib3MF::Impl::CConsumer::GetConsumerID() {
|
||||
return m_Consumer->getConsumerID();
|
||||
}
|
||||
|
||||
std::string Lib3MF::Impl::CConsumer::GetKeyID() {
|
||||
return m_Consumer->getKeyID();
|
||||
}
|
||||
|
||||
std::string Lib3MF::Impl::CConsumer::GetKeyValue() {
|
||||
return m_Consumer->getKeyValue();
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "lib3mf_contentencryptionparams.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
|
||||
namespace Lib3MF {
|
||||
namespace Impl {
|
||||
CContentEncryptionParams::CContentEncryptionParams(NMR::PCKeyStoreContentEncryptionParams const & p): m_pParams(p) {
|
||||
if (!p)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
|
||||
Lib3MF_uint64 CContentEncryptionParams::GetDescriptor() {
|
||||
return m_pParams->getDescriptor();
|
||||
}
|
||||
|
||||
eEncryptionAlgorithm CContentEncryptionParams::GetEncryptionAlgorithm() {
|
||||
return(eEncryptionAlgorithm)m_pParams->getEncryptionAlgorithm();
|
||||
}
|
||||
|
||||
void CContentEncryptionParams::GetKey(Lib3MF_uint64 nByteDataBufferSize, Lib3MF_uint64 *pByteDataNeededCount, Lib3MF_uint8 *pByteDataBuffer) {
|
||||
const std::vector<NMR::nfByte> & buf = m_pParams->getKey();
|
||||
if (nByteDataBufferSize < buf.size() || nullptr == pByteDataBuffer)
|
||||
*pByteDataNeededCount = buf.size();
|
||||
else {
|
||||
std::copy(buf.begin(), buf.end(), pByteDataBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void CContentEncryptionParams::GetInitializationVector(Lib3MF_uint64 nByteDataBufferSize, Lib3MF_uint64 *pByteDataNeededCount, Lib3MF_uint8 *pByteDataBuffer) {
|
||||
const std::vector<NMR::nfByte> & buf = m_pParams->getInitVector();
|
||||
if (nByteDataBufferSize < buf.size() || nullptr == pByteDataBuffer)
|
||||
*pByteDataNeededCount = buf.size();
|
||||
else {
|
||||
std::copy(buf.begin(), buf.end(), pByteDataBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void CContentEncryptionParams::GetAuthenticationTag(Lib3MF_uint64 nByteDataBufferSize, Lib3MF_uint64 *pByteDataNeededCount, Lib3MF_uint8 *pByteDataBuffer) {
|
||||
const std::vector<NMR::nfByte> & buf = m_pParams->getAuthTag();
|
||||
if (nByteDataBufferSize < buf.size() || nullptr == pByteDataBuffer)
|
||||
*pByteDataNeededCount = buf.size();
|
||||
else {
|
||||
std::copy(buf.begin(), buf.end(), pByteDataBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void CContentEncryptionParams::SetAuthenticationTag(Lib3MF_uint64 const nByteDataBufferSize, const Lib3MF_uint8 *pByteDataBuffer) {
|
||||
std::vector<NMR::nfByte> tag(pByteDataBuffer, pByteDataBuffer + nByteDataBufferSize);
|
||||
m_pParams->setAuthTag(tag);
|
||||
}
|
||||
|
||||
void CContentEncryptionParams::GetAdditionalAuthenticationData(Lib3MF_uint64 nByteDataBufferSize, Lib3MF_uint64 *pByteDataNeededCount, Lib3MF_uint8 *pByteDataBuffer) {
|
||||
const std::vector<NMR::nfByte> & buf = m_pParams->getAddAuthData();
|
||||
if (nByteDataBufferSize < buf.size() || nullptr == pByteDataBuffer)
|
||||
*pByteDataNeededCount = buf.size();
|
||||
else {
|
||||
std::copy(buf.begin(), buf.end(), pByteDataBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void CContentEncryptionParams::SetAdditionalAuthenticationData(Lib3MF_uint64 const nByteDataBufferSize, const Lib3MF_uint8 *pByteDataBuffer) {
|
||||
std::vector<NMR::nfByte> aad(pByteDataBuffer, pByteDataBuffer + nByteDataBufferSize);
|
||||
m_pParams->setAddAuthData(aad);
|
||||
}
|
||||
|
||||
std::string CContentEncryptionParams::GetKeyUUID() {
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
#include "lib3mf_types.hpp"
|
||||
#include "lib3mf_keystore.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
#include "lib3mf_consumer.hpp"
|
||||
#include "lib3mf_resourcedatagroup.hpp"
|
||||
#include "lib3mf_resourcedata.hpp"
|
||||
#include "lib3mf_packagepart.hpp"
|
||||
#include "lib3mf_utils.hpp"
|
||||
|
||||
#include "Model/Classes/NMR_KeyStoreFactory.h"
|
||||
#include "Model/Classes/NMR_PackageResourceID.h"
|
||||
#include "Model/Classes/NMR_Model.h"
|
||||
#include "Common/NMR_SecureContentTypes.h"
|
||||
#include "Common/NMR_Types.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
Lib3MF::Impl::CKeyStore::CKeyStore(NMR::PModel const & pModel)
|
||||
:m_pModel(pModel)
|
||||
{
|
||||
if (nullptr == pModel)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDKEYSTORE);
|
||||
m_pKeyStore = pModel->getKeyStore();
|
||||
}
|
||||
|
||||
IConsumer * Lib3MF::Impl::CKeyStore::AddConsumer(const std::string & sConsumerID, const std::string & sKeyID, const std::string & sKeyValue)
|
||||
{
|
||||
NMR::PKeyStoreConsumer consumer = NMR::CKeyStoreFactory::makeConsumer(sConsumerID);
|
||||
consumer->setKeyID(sKeyID);
|
||||
consumer->setKeyValue(sKeyValue);
|
||||
m_pKeyStore->addConsumer(consumer);
|
||||
return new CConsumer(consumer);
|
||||
}
|
||||
|
||||
Lib3MF_uint64 Lib3MF::Impl::CKeyStore::GetConsumerCount()
|
||||
{
|
||||
return m_pKeyStore->getConsumerCount();
|
||||
}
|
||||
|
||||
IConsumer * Lib3MF::Impl::CKeyStore::GetConsumer(const Lib3MF_uint64 nConsumerIndex)
|
||||
{
|
||||
NMR::PKeyStoreConsumer consumer = m_pKeyStore->getConsumer(nConsumerIndex);
|
||||
return new CConsumer(consumer);
|
||||
}
|
||||
|
||||
IConsumer * Lib3MF::Impl::CKeyStore::FindConsumer(const std::string & sConsumerID)
|
||||
{
|
||||
NMR::PKeyStoreConsumer consumer = m_pKeyStore->findConsumerById(sConsumerID);
|
||||
if (!consumer)
|
||||
return nullptr;
|
||||
return new CConsumer(consumer);
|
||||
}
|
||||
|
||||
void Lib3MF::Impl::CKeyStore::RemoveConsumer(IConsumer * pConsumerInstance)
|
||||
{
|
||||
CConsumer * pConsumer = dynamic_cast<CConsumer *>(pConsumerInstance);
|
||||
if (!pConsumer) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDKEYSTORECONSUMER);
|
||||
}
|
||||
m_pKeyStore->removeConsumer(pConsumer->consumer());
|
||||
}
|
||||
|
||||
std::string Lib3MF::Impl::CKeyStore::GetUUID(bool & bHasUUID) {
|
||||
bHasUUID = m_pKeyStore->getUUID() != nullptr;
|
||||
if (bHasUUID)
|
||||
return m_pKeyStore->getUUID()->toString();
|
||||
return "";
|
||||
}
|
||||
|
||||
void Lib3MF::Impl::CKeyStore::SetUUID(const std::string & sUUID)
|
||||
{
|
||||
NMR::PUUID pUUID = std::make_shared<NMR::CUUID>(sUUID);
|
||||
m_pKeyStore->setUUID(pUUID);
|
||||
}
|
||||
|
||||
Lib3MF_uint64 Lib3MF::Impl::CKeyStore::GetResourceDataGroupCount()
|
||||
{
|
||||
return (Lib3MF_uint32)m_pKeyStore->getResourceDataGroupCount();
|
||||
}
|
||||
|
||||
IResourceDataGroup * Lib3MF::Impl::CKeyStore::GetResourceDataGroup(const Lib3MF_uint64 nResourceDataIndex)
|
||||
{
|
||||
NMR::PKeyStoreResourceDataGroup dg = m_pKeyStore->getResourceDataGroup(nResourceDataIndex);
|
||||
return new CResourceDataGroup(dg);
|
||||
}
|
||||
|
||||
IResourceDataGroup * Lib3MF::Impl::CKeyStore::AddResourceDataGroup() {
|
||||
//this is not ideal, as key size is determined by the encryptionalgorithm inside resourcedata.
|
||||
//in any case, the spec does not state what happens if different resource datas have different algorithms,
|
||||
//but resourcedatagroups are supposed to group the same key for a group of resources...
|
||||
//so far, this should work as aes256 is the only thing we support.
|
||||
std::vector<NMR::nfByte> key(NMR::fnGetAlgorithmKeySize(NMR::eKeyStoreEncryptAlgorithm::AES256_GCM), 0);
|
||||
m_pModel->generateRandomBytes(key.data(), key.size());
|
||||
NMR::PKeyStoreResourceDataGroup dg = NMR::CKeyStoreFactory::makeResourceDataGroup(std::make_shared<NMR::CUUID>(), key);
|
||||
m_pKeyStore->addResourceDataGroup(dg);
|
||||
return new CResourceDataGroup(dg);
|
||||
}
|
||||
|
||||
void Lib3MF::Impl::CKeyStore::RemoveResourceDataGroup(IResourceDataGroup * pTheResourceDataGroup) {
|
||||
CResourceDataGroup * dg = dynamic_cast<CResourceDataGroup *>(pTheResourceDataGroup);
|
||||
if (!dg)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
m_pKeyStore->removeResourceDataGroup(dg->resourceDataGroup());
|
||||
}
|
||||
|
||||
Lib3MF::Impl::IResourceDataGroup * Lib3MF::Impl::CKeyStore::FindResourceDataGroup(Lib3MF::Impl::IPackagePart *pPartPath) {
|
||||
NMR::PPackageModelPath pPath = m_pModel->findOrCreateModelPath(pPartPath->GetPath());
|
||||
if (!pPath)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
NMR::PKeyStoreResourceDataGroup dg = m_pKeyStore->findResourceDataGroupByResourceDataPath(pPath);
|
||||
if (!dg)
|
||||
return nullptr;
|
||||
return new CResourceDataGroup(dg);
|
||||
}
|
||||
|
||||
Lib3MF::Impl::IResourceData * Lib3MF::Impl::CKeyStore::AddResourceData(Lib3MF::Impl::IResourceDataGroup *pResourceDataGroup, Lib3MF::Impl::IPackagePart *pPartPath, Lib3MF::eEncryptionAlgorithm eAlgorithm, Lib3MF::eCompression eCompression, Lib3MF_uint64 nAdditionalAuthenticationDataBufferSize, const Lib3MF_uint8 *pAdditionalAuthenticationDataBuffer) {
|
||||
bool compression = translateCompression(eCompression);
|
||||
NMR::eKeyStoreEncryptAlgorithm algorithm = translateEncryptionAlgorithm(eAlgorithm);
|
||||
CResourceDataGroup * dg = dynamic_cast<CResourceDataGroup *>(pResourceDataGroup);
|
||||
if (!dg)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
//pPartPath might have different implementations, so asking model get us right to what we need.
|
||||
NMR::PPackageModelPath pPath = m_pModel->findOrCreateModelPath(pPartPath->GetPath());
|
||||
if (!pPath)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
std::vector<NMR::nfByte> aad(pAdditionalAuthenticationDataBuffer, pAdditionalAuthenticationDataBuffer + nAdditionalAuthenticationDataBufferSize);
|
||||
NMR::PKeyStoreCEKParams params = NMR::CKeyStoreFactory::makeCEKParams(compression, algorithm, aad);
|
||||
NMR::PKeyStoreResourceData rd = NMR::CKeyStoreFactory::makeResourceData(dg->resourceDataGroup(), pPath, params);
|
||||
m_pKeyStore->addResourceData(rd);
|
||||
return new CResourceData(rd);
|
||||
}
|
||||
|
||||
void Lib3MF::Impl::CKeyStore::RemoveResourceData(Lib3MF::Impl::IResourceData *pResourceData) {
|
||||
CResourceData * rd = dynamic_cast<CResourceData *>(pResourceData);
|
||||
if (!rd)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
m_pKeyStore->removeResourceData(rd->resourceData());
|
||||
}
|
||||
|
||||
Lib3MF_uint64 Lib3MF::Impl::CKeyStore::GetResourceDataCount() {
|
||||
return m_pKeyStore->getResourceDataCount();
|
||||
}
|
||||
|
||||
Lib3MF::Impl::IResourceData * Lib3MF::Impl::CKeyStore::GetResourceData(Lib3MF_uint64 nResourceDataIndex) {
|
||||
NMR::PKeyStoreResourceData rd = m_pKeyStore->getResourceData(nResourceDataIndex);
|
||||
return new CResourceData(rd);
|
||||
}
|
||||
|
||||
IResourceData * Lib3MF::Impl::CKeyStore::FindResourceData(IPackagePart * pResourcePath) {
|
||||
NMR::PPackageModelPath pPath = m_pModel->findOrCreateModelPath(pResourcePath->GetPath());
|
||||
if (!pPath)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
NMR::PKeyStoreResourceData rd = m_pKeyStore->findResourceData(pPath);
|
||||
if (!rd)
|
||||
return nullptr;
|
||||
return new CResourceData(rd);
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CMeshObject
|
||||
|
||||
*/
|
||||
#include "lib3mf_meshobject.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
#include "lib3mf_beamlattice.hpp"
|
||||
// Include custom headers here.
|
||||
|
||||
#include "Common/MeshInformation/NMR_MeshInformation_Properties.h"
|
||||
#include <cmath>
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CMeshObject
|
||||
**************************************************************************************************************************/
|
||||
|
||||
IMeshObject* CMeshObject::fnCreateMeshObjectFromModelResource(NMR::PModelResource pResource, bool bFailIfUnkownClass) {
|
||||
|
||||
if (!pResource.get())
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
NMR::CModelMeshObject * pMeshObject = dynamic_cast<NMR::CModelMeshObject *> (pResource.get());
|
||||
if (pMeshObject) {
|
||||
return new CMeshObject(pResource);
|
||||
}
|
||||
|
||||
if (bFailIfUnkownClass)
|
||||
throw ELib3MFInterfaceException(NMR_ERROR_UNKNOWNMODELRESOURCE);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NMR::CMeshInformation_Properties* CMeshObject::getMeshInformationProperties()
|
||||
{
|
||||
auto pMesh = mesh();
|
||||
auto pInformationHandler = pMesh->createMeshInformationHandler();
|
||||
NMR::CMeshInformation_Properties * pInformation = dynamic_cast<NMR::CMeshInformation_Properties *> (pInformationHandler->getInformationByType(0, NMR::emiProperties));
|
||||
|
||||
if (pInformation == nullptr) {
|
||||
NMR::PMeshInformation_Properties pNewInformation = std::make_shared<NMR::CMeshInformation_Properties>(pMesh->getFaceCount());
|
||||
pInformationHandler->addInformation(pNewInformation);
|
||||
|
||||
pInformation = pNewInformation.get();
|
||||
}
|
||||
return pInformation;
|
||||
}
|
||||
|
||||
CMeshObject::CMeshObject(NMR::PModelResource pResource)
|
||||
: CResource(pResource), CObject(pResource)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NMR::PModelMeshObject CMeshObject::meshObject()
|
||||
{
|
||||
NMR::PModelMeshObject pMesh = std::dynamic_pointer_cast<NMR::CModelMeshObject>(resource());
|
||||
if (pMesh == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDOBJECT);
|
||||
return pMesh;
|
||||
}
|
||||
|
||||
NMR::CMesh* CMeshObject::mesh()
|
||||
{
|
||||
return meshObject()->getMesh();
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CMeshObject::GetVertexCount ()
|
||||
{
|
||||
return mesh()->getNodeCount();
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CMeshObject::GetTriangleCount ()
|
||||
{
|
||||
return mesh()->getFaceCount();
|
||||
}
|
||||
|
||||
void CMeshObject::SetVertex (const Lib3MF_uint32 nIndex, const sLib3MFPosition Coordinates)
|
||||
{
|
||||
NMR::MESHNODE* node = mesh()->getNode(nIndex);
|
||||
node->m_position.m_fields[0] = Coordinates.m_Coordinates[0];
|
||||
node->m_position.m_fields[1] = Coordinates.m_Coordinates[1];
|
||||
node->m_position.m_fields[2] = Coordinates.m_Coordinates[2];
|
||||
}
|
||||
|
||||
sLib3MFPosition CMeshObject::GetVertex(const Lib3MF_uint32 nIndex)
|
||||
{
|
||||
NMR::MESHNODE* node = mesh()->getNode(nIndex);
|
||||
sLib3MFPosition pos;
|
||||
pos.m_Coordinates[0] = node->m_position.m_fields[0];
|
||||
pos.m_Coordinates[1] = node->m_position.m_fields[1];
|
||||
pos.m_Coordinates[2] = node->m_position.m_fields[2];
|
||||
return pos;
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CMeshObject::AddVertex (const sLib3MFPosition Coordinates)
|
||||
{
|
||||
return mesh()->addNode(Coordinates.m_Coordinates[0], Coordinates.m_Coordinates[1], Coordinates.m_Coordinates[2])->m_index;
|
||||
}
|
||||
|
||||
void CMeshObject::GetVertices(Lib3MF_uint64 nVerticesBufferSize, Lib3MF_uint64* pVerticesNeededCount, sLib3MFPosition * pVerticesBuffer)
|
||||
{
|
||||
Lib3MF_uint32 nodeCount = mesh()->getNodeCount();
|
||||
if (pVerticesNeededCount)
|
||||
*pVerticesNeededCount = nodeCount;
|
||||
|
||||
if (nVerticesBufferSize >= nodeCount && pVerticesBuffer)
|
||||
{
|
||||
for (Lib3MF_uint32 i = 0; i < nodeCount; i++)
|
||||
{
|
||||
const NMR::MESHNODE* node = mesh()->getNode(i);
|
||||
pVerticesBuffer[i].m_Coordinates[0] = node->m_position.m_fields[0];
|
||||
pVerticesBuffer[i].m_Coordinates[1] = node->m_position.m_fields[1];
|
||||
pVerticesBuffer[i].m_Coordinates[2] = node->m_position.m_fields[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sLib3MFTriangle CMeshObject::GetTriangle (const Lib3MF_uint32 nIndex)
|
||||
{
|
||||
sLib3MFTriangle t;
|
||||
NMR::MESHFACE* mf = mesh()->getFace(nIndex);
|
||||
|
||||
t.m_Indices[0] = mf->m_nodeindices[0];
|
||||
t.m_Indices[1] = mf->m_nodeindices[1];
|
||||
t.m_Indices[2] = mf->m_nodeindices[2];
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void CMeshObject::SetTriangle (const Lib3MF_uint32 nIndex, const sLib3MFTriangle Indices)
|
||||
{
|
||||
NMR::MESHFACE* mf = mesh()->getFace(nIndex);
|
||||
|
||||
mf->m_nodeindices[0] = Indices.m_Indices[0];
|
||||
mf->m_nodeindices[1] = Indices.m_Indices[1];
|
||||
mf->m_nodeindices[2] = Indices.m_Indices[2];
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CMeshObject::AddTriangle(const sLib3MFTriangle Indices)
|
||||
{
|
||||
return mesh()->addFace(Indices.m_Indices[0], Indices.m_Indices[1], Indices.m_Indices[2])->m_index;
|
||||
}
|
||||
|
||||
void CMeshObject::GetTriangleIndices (Lib3MF_uint64 nIndicesBufferSize, Lib3MF_uint64* pIndicesNeededCount, sLib3MFTriangle * pIndicesBuffer)
|
||||
{
|
||||
Lib3MF_uint32 faceCount = mesh()->getFaceCount();
|
||||
if (pIndicesNeededCount)
|
||||
*pIndicesNeededCount = faceCount;
|
||||
|
||||
if (nIndicesBufferSize >= faceCount && pIndicesBuffer)
|
||||
{
|
||||
for (Lib3MF_uint32 i = 0; i < faceCount; i++)
|
||||
{
|
||||
const NMR::MESHFACE* face = mesh()->getFace(i);
|
||||
pIndicesBuffer[i].m_Indices[0] = face->m_nodeindices[0];
|
||||
pIndicesBuffer[i].m_Indices[1] = face->m_nodeindices[1];
|
||||
pIndicesBuffer[i].m_Indices[2] = face->m_nodeindices[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMeshObject::SetObjectLevelProperty(const Lib3MF_uint32 nUniqueResourceID, const Lib3MF_uint32 nPropertyID)
|
||||
{
|
||||
NMR::CMeshInformation_Properties * pInformation = getMeshInformationProperties();
|
||||
|
||||
NMR::MESHINFORMATION_PROPERTIES * pDefaultData = new NMR::MESHINFORMATION_PROPERTIES;
|
||||
pDefaultData->m_nUniqueResourceID = nUniqueResourceID;
|
||||
pDefaultData->m_nPropertyIDs[0] = nPropertyID;
|
||||
pDefaultData->m_nPropertyIDs[1] = nPropertyID;
|
||||
pDefaultData->m_nPropertyIDs[2] = nPropertyID;
|
||||
|
||||
pInformation->setDefaultData((NMR::MESHINFORMATIONFACEDATA*)pDefaultData);
|
||||
}
|
||||
|
||||
bool CMeshObject::GetObjectLevelProperty(Lib3MF_uint32 & nUniqueResourceID, Lib3MF_uint32 & nPropertyID)
|
||||
{
|
||||
NMR::CMeshInformation_Properties * pInformation = getMeshInformationProperties();
|
||||
|
||||
NMR::MESHINFORMATION_PROPERTIES * pDefaultData = (NMR::MESHINFORMATION_PROPERTIES*)pInformation->getDefaultData();
|
||||
if (pDefaultData) {
|
||||
nUniqueResourceID = pDefaultData->m_nUniqueResourceID;
|
||||
nPropertyID = pDefaultData->m_nPropertyIDs[0];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CMeshObject::SetTriangleProperties(const Lib3MF_uint32 nIndex, const sLib3MFTriangleProperties Properties)
|
||||
{
|
||||
NMR::CMeshInformation_Properties * pInformation = getMeshInformationProperties();
|
||||
|
||||
NMR::MESHINFORMATION_PROPERTIES * pFaceData = (NMR::MESHINFORMATION_PROPERTIES*)pInformation->getFaceData(nIndex);
|
||||
if (pFaceData != nullptr) {
|
||||
pFaceData->m_nUniqueResourceID = Properties.m_ResourceID;
|
||||
for (unsigned j = 0; j < 3; j++) {
|
||||
pFaceData->m_nPropertyIDs[j] = Properties.m_PropertyIDs[j];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CMeshObject::GetTriangleProperties(const Lib3MF_uint32 nIndex, sLib3MFTriangleProperties & sProperty)
|
||||
{
|
||||
NMR::CMeshInformation_Properties * pInformation = getMeshInformationProperties();
|
||||
|
||||
NMR::MESHINFORMATION_PROPERTIES * pFaceData = (NMR::MESHINFORMATION_PROPERTIES*)pInformation->getFaceData(nIndex);
|
||||
if (pFaceData != nullptr) {
|
||||
sProperty.m_ResourceID = pFaceData->m_nUniqueResourceID;
|
||||
for (unsigned j = 0; j < 3; j++) {
|
||||
sProperty.m_PropertyIDs[j] = pFaceData->m_nPropertyIDs[j];
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
sProperty.m_ResourceID = 0;
|
||||
for (unsigned j = 0; j < 3; j++) {
|
||||
sProperty.m_PropertyIDs[j] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void CMeshObject::SetAllTriangleProperties(const Lib3MF_uint64 nPropertiesArrayBufferSize, const sLib3MFTriangleProperties * pPropertiesArrayBuffer)
|
||||
{
|
||||
auto pMesh = mesh();
|
||||
uint32_t nFaceCount = pMesh->getFaceCount();
|
||||
|
||||
if (nPropertiesArrayBufferSize != nFaceCount)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPROPERTYCOUNT);
|
||||
if (pPropertiesArrayBuffer == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
NMR::CMeshInformation_Properties * pInformation = getMeshInformationProperties();
|
||||
|
||||
const sLib3MFTriangleProperties * pProperty = pPropertiesArrayBuffer;
|
||||
|
||||
for (uint32_t nIndex = 0; nIndex < nFaceCount; nIndex++) {
|
||||
NMR::MESHINFORMATION_PROPERTIES * pFaceData = (NMR::MESHINFORMATION_PROPERTIES*)pInformation->getFaceData(nIndex);
|
||||
if (pFaceData != nullptr) {
|
||||
pFaceData->m_nUniqueResourceID = pProperty->m_ResourceID;
|
||||
for (unsigned j = 0; j < 3; j++) {
|
||||
pFaceData->m_nPropertyIDs[j] = pProperty->m_PropertyIDs[j];
|
||||
}
|
||||
}
|
||||
pProperty++;
|
||||
}
|
||||
|
||||
// Prepare an object-level property, if it makes sense to do so
|
||||
if ((nFaceCount > 0) && (pInformation->getDefaultData() == nullptr)) {
|
||||
NMR::MESHINFORMATION_PROPERTIES * pFaceData = (NMR::MESHINFORMATION_PROPERTIES*)pInformation->getFaceData(0);
|
||||
std::unique_ptr<NMR::MESHINFORMATION_PROPERTIES> pDefaultFaceData(new NMR::MESHINFORMATION_PROPERTIES);
|
||||
pDefaultFaceData->m_nUniqueResourceID = pFaceData->m_nUniqueResourceID;
|
||||
for (unsigned j = 0; j < 3; j++) {
|
||||
pDefaultFaceData->m_nPropertyIDs[j] = pFaceData->m_nPropertyIDs[j];
|
||||
}
|
||||
pInformation->setDefaultData((NMR::MESHINFORMATIONFACEDATA*)pDefaultFaceData.release());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CMeshObject::GetAllTriangleProperties(Lib3MF_uint64 nPropertiesArrayBufferSize, Lib3MF_uint64* pPropertiesArrayNeededCount, sLib3MFTriangleProperties * pPropertiesArrayBuffer)
|
||||
{
|
||||
auto pMesh = mesh();
|
||||
uint32_t nFaceCount = pMesh->getFaceCount();
|
||||
|
||||
if (pPropertiesArrayNeededCount)
|
||||
*pPropertiesArrayNeededCount = nFaceCount;
|
||||
|
||||
if (nPropertiesArrayBufferSize >= nFaceCount && pPropertiesArrayBuffer)
|
||||
{
|
||||
NMR::CMeshInformation_Properties * pInformation = getMeshInformationProperties();
|
||||
|
||||
sLib3MFTriangleProperties * pProperty = pPropertiesArrayBuffer;
|
||||
|
||||
uint32_t nIndex;
|
||||
for (nIndex = 0; nIndex < nFaceCount; nIndex++) {
|
||||
|
||||
NMR::MESHINFORMATION_PROPERTIES * pFaceData = (NMR::MESHINFORMATION_PROPERTIES*)pInformation->getFaceData(nIndex);
|
||||
if (pFaceData != nullptr) {
|
||||
pProperty->m_ResourceID = pFaceData->m_nUniqueResourceID;
|
||||
for (unsigned j = 0; j < 3; j++) {
|
||||
pProperty->m_PropertyIDs[j] = pFaceData->m_nPropertyIDs[j];
|
||||
}
|
||||
}
|
||||
pProperty++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMeshObject::ClearAllProperties()
|
||||
{
|
||||
mesh()->clearMeshInformationHandler();
|
||||
}
|
||||
|
||||
void CMeshObject::SetGeometry(const Lib3MF_uint64 nVerticesBufferSize, const sLib3MFPosition * pVerticesBuffer, const Lib3MF_uint64 nIndicesBufferSize, const sLib3MFTriangle * pIndicesBuffer)
|
||||
{
|
||||
if ( ((!pVerticesBuffer) && (nVerticesBufferSize>0)) || ((!pIndicesBuffer) && (nIndicesBufferSize>0)))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
NMR::CMesh * pMesh = mesh();
|
||||
|
||||
// Clear old mesh
|
||||
pMesh->clear();
|
||||
|
||||
// Rebuild Mesh Coordinates
|
||||
const sLib3MFPosition * pVertex = pVerticesBuffer;
|
||||
for (Lib3MF_uint64 nIndex = 0; nIndex < nVerticesBufferSize; nIndex++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (std::fabs(pVertex->m_Coordinates[j]) > NMR_MESH_MAXCOORDINATE)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
pMesh->addNode(pVertex->m_Coordinates[0], pVertex->m_Coordinates[1], pVertex->m_Coordinates[2]);
|
||||
|
||||
pVertex++;
|
||||
}
|
||||
|
||||
// Rebuild Mesh Faces
|
||||
const sLib3MFTriangle * pTriangle = pIndicesBuffer;
|
||||
for (Lib3MF_uint64 nIndex = 0; nIndex < nIndicesBufferSize; nIndex++) {
|
||||
NMR::MESHNODE * pNodes[3];
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (pTriangle->m_Indices[j] >= nVerticesBufferSize)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
pNodes[j] = pMesh->getNode(pTriangle->m_Indices[j]);
|
||||
}
|
||||
|
||||
if ((pTriangle->m_Indices[0] == pTriangle->m_Indices[1]) ||
|
||||
(pTriangle->m_Indices[0] == pTriangle->m_Indices[2]) ||
|
||||
(pTriangle->m_Indices[1] == pTriangle->m_Indices[2]))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
pMesh->addFace(pNodes[0], pNodes[1], pNodes[2]);
|
||||
|
||||
pTriangle++;
|
||||
}
|
||||
}
|
||||
|
||||
bool CMeshObject::IsManifoldAndOriented ()
|
||||
{
|
||||
return meshObject()->isManifoldAndOriented();
|
||||
}
|
||||
|
||||
bool CMeshObject::IsMeshObject()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CMeshObject::IsComponentsObject()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CMeshObject::IsValid()
|
||||
{
|
||||
return meshObject()->isValid();
|
||||
}
|
||||
|
||||
IBeamLattice* CMeshObject::BeamLattice()
|
||||
{
|
||||
return new CBeamLattice(meshObject(), meshObject()->getBeamLatticeAttributes());
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CMeshObjectIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_meshobjectiterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_meshobject.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CObjectIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
IMeshObject * CMeshObjectIterator::GetCurrentMeshObject ()
|
||||
{
|
||||
return CMeshObject::fnCreateMeshObjectFromModelResource(GetCurrentResource(), true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CMetaData
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_metadata.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CMetaData
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CMetaData::CMetaData(NMR::PModelMetaData pMetaData)
|
||||
:m_pMetaData(pMetaData)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string CMetaData::GetNameSpace ()
|
||||
{
|
||||
return m_pMetaData->getNameSpace();
|
||||
}
|
||||
|
||||
void CMetaData::SetNameSpace (const std::string & sNameSpace)
|
||||
{
|
||||
m_pMetaData->setNameSpace(sNameSpace);
|
||||
}
|
||||
|
||||
std::string CMetaData::GetName()
|
||||
{
|
||||
return m_pMetaData->getName();
|
||||
}
|
||||
|
||||
std::string CMetaData::GetKey()
|
||||
{
|
||||
return m_pMetaData->getKey();
|
||||
}
|
||||
|
||||
void CMetaData::SetName (const std::string & sName)
|
||||
{
|
||||
m_pMetaData->setName(sName);
|
||||
}
|
||||
|
||||
bool CMetaData::GetMustPreserve ()
|
||||
{
|
||||
return m_pMetaData->getPreserve();
|
||||
}
|
||||
|
||||
void CMetaData::SetMustPreserve (const bool bMustPreserve)
|
||||
{
|
||||
m_pMetaData->setPreserve(bMustPreserve);
|
||||
}
|
||||
|
||||
std::string CMetaData::GetType ()
|
||||
{
|
||||
return m_pMetaData->getType();
|
||||
}
|
||||
|
||||
void CMetaData::SetType (const std::string & sType)
|
||||
{
|
||||
m_pMetaData->setType(sType);
|
||||
}
|
||||
|
||||
std::string CMetaData::GetValue ()
|
||||
{
|
||||
return m_pMetaData->getValue();
|
||||
}
|
||||
|
||||
void CMetaData::SetValue (const std::string & sValue)
|
||||
{
|
||||
m_pMetaData->setValue(sValue);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CMetaDataGroup
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_metadatagroup.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
#include "lib3mf_metadata.hpp"
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CMetaDataGroup
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CMetaDataGroup::CMetaDataGroup(NMR::PModelMetaDataGroup pMetaDataGroup)
|
||||
: m_pModelMetaDataGroup(pMetaDataGroup)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CMetaDataGroup::GetMetaDataCount ()
|
||||
{
|
||||
return m_pModelMetaDataGroup->getMetaDataCount();
|
||||
}
|
||||
|
||||
IMetaData * CMetaDataGroup::GetMetaData (const Lib3MF_uint32 nIndex)
|
||||
{
|
||||
return new CMetaData(m_pModelMetaDataGroup->getMetaData(nIndex));
|
||||
}
|
||||
|
||||
IMetaData * CMetaDataGroup::GetMetaDataByKey (const std::string & sNameSpace, const std::string & sName)
|
||||
{
|
||||
for (NMR::nfUint32 i = 0; i < m_pModelMetaDataGroup->getMetaDataCount(); i++) {
|
||||
NMR::PModelMetaData pMetaData = m_pModelMetaDataGroup->getMetaData(i);
|
||||
if (sNameSpace.empty()) {
|
||||
if (pMetaData->getName() == sName) {
|
||||
return new CMetaData(pMetaData);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pMetaData->getKey() == sNameSpace + ":" + sName) {
|
||||
return new CMetaData(pMetaData);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
|
||||
void CMetaDataGroup::RemoveMetaDataByIndex (const Lib3MF_uint32 nIndex)
|
||||
{
|
||||
m_pModelMetaDataGroup->removeMetaData(nIndex);
|
||||
}
|
||||
|
||||
void CMetaDataGroup::RemoveMetaData(IMetaData* pTheMetaData)
|
||||
{
|
||||
for (NMR::nfUint32 i = 0; i < m_pModelMetaDataGroup->getMetaDataCount(); i++) {
|
||||
NMR::PModelMetaData pMetaData = m_pModelMetaDataGroup->getMetaData(i);
|
||||
if (pTheMetaData->GetName() == pMetaData->getName()) {
|
||||
m_pModelMetaDataGroup->removeMetaData(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
|
||||
IMetaData * CMetaDataGroup::AddMetaData(const std::string & sNameSpace, const std::string & sName, const std::string & sValue, const std::string & sType, const bool bMustPreserve)
|
||||
{
|
||||
NMR::PModelMetaData pModelMetaData = m_pModelMetaDataGroup->addMetaData(sNameSpace, sName, sValue, sType, bMustPreserve);
|
||||
return new CMetaData(pModelMetaData);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,708 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CModel
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_model.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
#include "lib3mf_reader.hpp"
|
||||
#include "lib3mf_writer.hpp"
|
||||
|
||||
#include "lib3mf_builditem.hpp"
|
||||
#include "lib3mf_builditemiterator.hpp"
|
||||
#include "lib3mf_meshobject.hpp"
|
||||
#include "lib3mf_objectiterator.hpp"
|
||||
#include "lib3mf_meshobjectiterator.hpp"
|
||||
#include "lib3mf_resourceiterator.hpp"
|
||||
#include "lib3mf_componentsobject.hpp"
|
||||
#include "lib3mf_componentsobjectiterator.hpp"
|
||||
#include "lib3mf_basematerialgroup.hpp"
|
||||
#include "lib3mf_metadatagroup.hpp"
|
||||
#include "lib3mf_attachment.hpp"
|
||||
#include "lib3mf_slicestack.hpp"
|
||||
#include "lib3mf_slicestackiterator.hpp"
|
||||
#include "lib3mf_texture2d.hpp"
|
||||
#include "lib3mf_texture2diterator.hpp"
|
||||
#include "lib3mf_basematerialgroupiterator.hpp"
|
||||
#include "lib3mf_colorgroup.hpp"
|
||||
#include "lib3mf_colorgroupiterator.hpp"
|
||||
#include "lib3mf_texture2dgroup.hpp"
|
||||
#include "lib3mf_texture2dgroupiterator.hpp"
|
||||
#include "lib3mf_compositematerials.hpp"
|
||||
#include "lib3mf_compositematerialsiterator.hpp"
|
||||
#include "lib3mf_multipropertygroup.hpp"
|
||||
#include "lib3mf_multipropertygroupiterator.hpp"
|
||||
#include "lib3mf_packagepart.hpp"
|
||||
#include "lib3mf_keystore.hpp"
|
||||
|
||||
|
||||
// Include custom headers here.
|
||||
#include "Model/Classes/NMR_ModelMeshObject.h"
|
||||
#include "Model/Classes/NMR_ModelComponentsObject.h"
|
||||
#include "Common/Platform/NMR_ImportStream_Unique_Memory.h"
|
||||
#include "Model/Classes/NMR_ModelColorGroup.h"
|
||||
#include "Model/Classes/NMR_ModelTexture2DGroup.h"
|
||||
#include "Model/Classes/NMR_ModelMultiPropertyGroup.h"
|
||||
#include "Common/NMR_SecureContentTypes.h"
|
||||
#include "lib3mf_utils.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CModel
|
||||
**************************************************************************************************************************/
|
||||
|
||||
|
||||
CModel::CModel()
|
||||
{
|
||||
m_model = std::make_shared<NMR::CModel>();
|
||||
}
|
||||
|
||||
NMR::CModel& CModel::model()
|
||||
{
|
||||
return *m_model;
|
||||
}
|
||||
|
||||
IPackagePart* CModel::RootModelPart()
|
||||
{
|
||||
return new CPackagePart(model().rootModelPath());
|
||||
}
|
||||
|
||||
IPackagePart * CModel::FindOrCreatePackagePart(const std::string & sAbsolutePath)
|
||||
{
|
||||
return new CPackagePart(model().findOrCreateModelPath(sAbsolutePath));
|
||||
}
|
||||
|
||||
void CModel::SetUnit (const eLib3MFModelUnit eUnit)
|
||||
{
|
||||
model().setUnit(NMR::eModelUnit(eUnit));
|
||||
}
|
||||
|
||||
eLib3MFModelUnit CModel::GetUnit ()
|
||||
{
|
||||
return eLib3MFModelUnit(model().getUnit());
|
||||
}
|
||||
|
||||
std::string CModel::GetLanguage ()
|
||||
{
|
||||
return model().getLanguage();
|
||||
}
|
||||
|
||||
void CModel::SetLanguage (const std::string & sLanguage)
|
||||
{
|
||||
model().setLanguage(sLanguage);
|
||||
}
|
||||
|
||||
IWriter * CModel::QueryWriter (const std::string & sWriterClass)
|
||||
{
|
||||
return new CWriter(sWriterClass, m_model);
|
||||
}
|
||||
|
||||
IReader * CModel::QueryReader (const std::string & sReaderClass)
|
||||
{
|
||||
return new CReader(sReaderClass, m_model);
|
||||
}
|
||||
|
||||
ITexture2D * CModel::GetTexture2DByID(const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
NMR::PModelTexture2DResource pTexture2DResource = model().findTexture2D(nUniqueResourceID);
|
||||
if (pTexture2DResource) {
|
||||
return new CTexture2D(pTexture2DResource);
|
||||
}
|
||||
else
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDTEXTURERESOURCE);
|
||||
}
|
||||
|
||||
eLib3MFPropertyType CModel::GetPropertyTypeByID(const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
NMR::PModelResource pResource = model().findResource(nUniqueResourceID);
|
||||
if (!pResource) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_RESOURCENOTFOUND);
|
||||
}
|
||||
|
||||
if (dynamic_cast<NMR::CModelBaseMaterialResource*>(pResource.get())) {
|
||||
return ePropertyType::BaseMaterial;
|
||||
}
|
||||
else if ((dynamic_cast<NMR::CModelColorGroupResource*>(pResource.get()))) {
|
||||
return ePropertyType::Colors;
|
||||
}
|
||||
else if ((dynamic_cast<NMR::CModelTexture2DGroupResource*>(pResource.get()))) {
|
||||
return ePropertyType::TexCoord;
|
||||
}
|
||||
else if ((dynamic_cast<NMR::CModelCompositeMaterialsResource*>(pResource.get()))) {
|
||||
return ePropertyType::Composite;
|
||||
}
|
||||
else if ((dynamic_cast<NMR::CModelMultiPropertyGroupResource*>(pResource.get()))) {
|
||||
return ePropertyType::Multi;
|
||||
}
|
||||
else
|
||||
return ePropertyType::NoPropertyType;
|
||||
}
|
||||
|
||||
IBaseMaterialGroup * CModel::GetBaseMaterialGroupByID(const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
NMR::PPackageResourceID pID = model().findPackageResourceID(nUniqueResourceID);
|
||||
if (pID) {
|
||||
NMR::PModelBaseMaterialResource pBaseMaterialResource = model().findBaseMaterial(pID);
|
||||
if (pBaseMaterialResource) {
|
||||
return new CBaseMaterialGroup(pBaseMaterialResource);
|
||||
}
|
||||
else
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDBASEMATERIALGROUP);
|
||||
}
|
||||
else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_RESOURCENOTFOUND);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IMeshObject * CModel::GetMeshObjectByID(const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
NMR::PModelResource pObjectResource = model().findResource(nUniqueResourceID);
|
||||
if (dynamic_cast<NMR::CModelMeshObject*>(pObjectResource.get())) {
|
||||
return new CMeshObject(pObjectResource);
|
||||
}
|
||||
else
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDMESHOBJECT);
|
||||
}
|
||||
|
||||
IComponentsObject * CModel::GetComponentsObjectByID(const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
NMR::PModelResource pObjectResource = model().findResource(nUniqueResourceID);
|
||||
if (dynamic_cast<NMR::CModelComponentsObject*>(pObjectResource.get())) {
|
||||
return new CComponentsObject(pObjectResource);
|
||||
}
|
||||
else
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCOMPONENTSOBJECT);
|
||||
}
|
||||
|
||||
IColorGroup * CModel::GetColorGroupByID(const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
NMR::PModelResource pResource = model().findResource(nUniqueResourceID);
|
||||
if (dynamic_cast<NMR::CModelColorGroupResource*>(pResource.get())) {
|
||||
return new CColorGroup(std::dynamic_pointer_cast<NMR::CModelColorGroupResource>(pResource));
|
||||
}
|
||||
else
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCOLORGROUP);
|
||||
}
|
||||
|
||||
ISliceStack * CModel::GetSliceStackByID(const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
NMR::PModelResource pResource = model().findResource(nUniqueResourceID);
|
||||
if (dynamic_cast<NMR::CModelSliceStack*>(pResource.get())) {
|
||||
return new CSliceStack(std::dynamic_pointer_cast<NMR::CModelSliceStack>(pResource));
|
||||
}
|
||||
else
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDSLICESTACKRESOURCE);
|
||||
}
|
||||
|
||||
ITexture2DGroup * CModel::GetTexture2DGroupByID(const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
NMR::PModelResource pResource = model().findResource(nUniqueResourceID);
|
||||
if (dynamic_cast<NMR::CModelTexture2DGroupResource*>(pResource.get())) {
|
||||
return new CTexture2DGroup(std::dynamic_pointer_cast<NMR::CModelTexture2DGroupResource>(pResource));
|
||||
}
|
||||
else
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDTEXTURE2DGROUP);
|
||||
}
|
||||
|
||||
ICompositeMaterials * CModel::GetCompositeMaterialsByID(const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
NMR::PModelResource pResource = model().findResource(nUniqueResourceID);
|
||||
if (dynamic_cast<NMR::CModelCompositeMaterialsResource*>(pResource.get())) {
|
||||
return new CCompositeMaterials(std::dynamic_pointer_cast<NMR::CModelCompositeMaterialsResource>(pResource));
|
||||
}
|
||||
else
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCOMPOSITEMATERIALS);
|
||||
}
|
||||
|
||||
IMultiPropertyGroup * CModel::GetMultiPropertyGroupByID(const Lib3MF_uint32 nUniqueResourceID)
|
||||
{
|
||||
NMR::PModelResource pResource = model().findResource(nUniqueResourceID);
|
||||
if (dynamic_cast<NMR::CModelMultiPropertyGroupResource*>(pResource.get())) {
|
||||
return new CMultiPropertyGroup(std::dynamic_pointer_cast<NMR::CModelMultiPropertyGroupResource>(pResource));
|
||||
}
|
||||
else
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDMULTIPROPERTYGROUP);
|
||||
}
|
||||
|
||||
std::string CModel::GetBuildUUID (bool & bHasUUID)
|
||||
{
|
||||
NMR::PUUID buildUUID = model().buildUUID();
|
||||
bHasUUID = buildUUID.get() != nullptr;
|
||||
if (bHasUUID)
|
||||
return buildUUID->toString();
|
||||
return "";
|
||||
}
|
||||
|
||||
void CModel::SetBuildUUID (const std::string & sUUID)
|
||||
{
|
||||
NMR::PUUID pUUID = std::make_shared<NMR::CUUID>(sUUID);
|
||||
model().setBuildUUID(pUUID);
|
||||
}
|
||||
|
||||
IBuildItemIterator * CModel::GetBuildItems ()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CBuildItemIterator>(new CBuildItemIterator());
|
||||
Lib3MF_uint32 nBuildItemCount = m_model->getBuildItemCount();
|
||||
Lib3MF_uint32 nIdx;
|
||||
|
||||
for (nIdx = 0; nIdx < nBuildItemCount; nIdx++)
|
||||
pResult->addBuildItem(m_model->getBuildItem(nIdx));
|
||||
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
IResourceIterator * CModel::GetResources ()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CResourceIterator>(new CResourceIterator());
|
||||
Lib3MF_uint32 nResourcesCount = model().getResourceCount();
|
||||
|
||||
for (Lib3MF_uint32 nIdx = 0; nIdx < nResourcesCount; nIdx++) {
|
||||
auto resource = model().getResource(nIdx);
|
||||
pResult->addResource(resource);
|
||||
}
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
IObjectIterator * CModel::GetObjects ()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CObjectIterator>(new CObjectIterator());
|
||||
Lib3MF_uint32 nObjectsCount = model().getObjectCount();
|
||||
|
||||
for (Lib3MF_uint32 nIdx = 0; nIdx < nObjectsCount; nIdx++) {
|
||||
auto resource = model().getObjectResource(nIdx);
|
||||
pResult->addResource(resource);
|
||||
}
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
IMeshObjectIterator * CModel::GetMeshObjects ()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CMeshObjectIterator>(new CMeshObjectIterator());
|
||||
Lib3MF_uint32 nObjectsCount = model().getObjectCount();
|
||||
|
||||
for (Lib3MF_uint32 nIdx = 0; nIdx < nObjectsCount; nIdx++) {
|
||||
auto resource = model().getObjectResource(nIdx);
|
||||
if (dynamic_cast<NMR::CModelMeshObject *>(resource.get()))
|
||||
pResult->addResource(resource);
|
||||
}
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
IComponentsObjectIterator * CModel::GetComponentsObjects()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CComponentsObjectIterator>(new CComponentsObjectIterator());
|
||||
Lib3MF_uint32 nObjectsCount = model().getObjectCount();
|
||||
|
||||
for (Lib3MF_uint32 nIdx = 0; nIdx < nObjectsCount; nIdx++) {
|
||||
auto resource = model().getObjectResource(nIdx);
|
||||
if (dynamic_cast<NMR::CModelComponentsObject *>(resource.get()))
|
||||
pResult->addResource(resource);
|
||||
}
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
ITexture2DIterator * CModel::GetTexture2Ds()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CTexture2DIterator>(new CTexture2DIterator());
|
||||
Lib3MF_uint32 nCount = model().getTexture2DCount();
|
||||
|
||||
for (Lib3MF_uint32 nIdx = 0; nIdx < nCount; nIdx++) {
|
||||
auto resource = model().getTexture2DResource(nIdx);
|
||||
if (dynamic_cast<NMR::CModelTexture2DResource *>(resource.get()))
|
||||
pResult->addResource(resource);
|
||||
}
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
IBaseMaterialGroupIterator * CModel::GetBaseMaterialGroups()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CBaseMaterialGroupIterator>(new CBaseMaterialGroupIterator());
|
||||
Lib3MF_uint32 nCount = model().getBaseMaterialCount();
|
||||
|
||||
for (Lib3MF_uint32 nIdx = 0; nIdx < nCount; nIdx++) {
|
||||
auto resource = model().getBaseMaterialResource(nIdx);
|
||||
if (dynamic_cast<NMR::CModelBaseMaterialResource *>(resource.get()))
|
||||
pResult->addResource(resource);
|
||||
}
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
IColorGroupIterator * CModel::GetColorGroups()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CColorGroupIterator>(new CColorGroupIterator());
|
||||
Lib3MF_uint32 nCount = model().getColorGroupCount();
|
||||
|
||||
for (Lib3MF_uint32 nIdx = 0; nIdx < nCount; nIdx++) {
|
||||
auto resource = model().getColorGroupResource(nIdx);
|
||||
if (dynamic_cast<NMR::CModelColorGroupResource *>(resource.get()))
|
||||
pResult->addResource(resource);
|
||||
}
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
ITexture2DGroupIterator * CModel::GetTexture2DGroups()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CTexture2DGroupIterator>(new CTexture2DGroupIterator());
|
||||
Lib3MF_uint32 nCount = model().getTexture2DGroupCount();
|
||||
|
||||
for (Lib3MF_uint32 nIdx = 0; nIdx < nCount; nIdx++) {
|
||||
auto resource = model().getTexture2DGroupResource(nIdx);
|
||||
if (dynamic_cast<NMR::CModelTexture2DGroupResource *>(resource.get()))
|
||||
pResult->addResource(resource);
|
||||
}
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
ICompositeMaterialsIterator * CModel::GetCompositeMaterials()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CCompositeMaterialsIterator>(new CCompositeMaterialsIterator());
|
||||
Lib3MF_uint32 nCount = model().getCompositeMaterialsCount();
|
||||
|
||||
for (Lib3MF_uint32 nIdx = 0; nIdx < nCount; nIdx++) {
|
||||
auto resource = model().getCompositeMaterialsResource(nIdx);
|
||||
if (dynamic_cast<NMR::CModelCompositeMaterialsResource *>(resource.get()))
|
||||
pResult->addResource(resource);
|
||||
}
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
IMultiPropertyGroupIterator * CModel::GetMultiPropertyGroups()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CMultiPropertyGroupIterator>(new CMultiPropertyGroupIterator());
|
||||
Lib3MF_uint32 nCount = model().getMultiPropertyGroupCount();
|
||||
|
||||
for (Lib3MF_uint32 nIdx = 0; nIdx < nCount; nIdx++) {
|
||||
auto resource = model().getMultiPropertyGroupResource(nIdx);
|
||||
if (dynamic_cast<NMR::CModelMultiPropertyGroupResource *>(resource.get()))
|
||||
pResult->addResource(resource);
|
||||
}
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
|
||||
ISliceStackIterator * CModel::GetSliceStacks()
|
||||
{
|
||||
auto pResult = std::unique_ptr<CSliceStackIterator>(new CSliceStackIterator());
|
||||
Lib3MF_uint32 nCount = model().getSliceStackCount();
|
||||
|
||||
for (Lib3MF_uint32 nIdx = 0; nIdx < nCount; nIdx++) {
|
||||
auto resource = model().getSliceStackResource(nIdx);
|
||||
if (dynamic_cast<NMR::CModelSliceStack *>(resource.get()))
|
||||
pResult->addResource(resource);
|
||||
}
|
||||
return pResult.release();
|
||||
}
|
||||
|
||||
IModel * CModel::MergeToModel ()
|
||||
{
|
||||
// Create merged mesh
|
||||
NMR::PMesh pMesh = std::make_shared<NMR::CMesh>();
|
||||
model().mergeToMesh(pMesh.get());
|
||||
|
||||
auto pOutModel = std::unique_ptr<CModel>(new CModel());
|
||||
|
||||
// Copy relevant resources to new model
|
||||
NMR::CModel& newModel = pOutModel->model();
|
||||
|
||||
NMR::UniqueResourceIDMapping oldToNewUniqueResourceIDs;
|
||||
|
||||
newModel.mergeModelAttachments(&model());
|
||||
newModel.mergeTextures2D(&model(), oldToNewUniqueResourceIDs);
|
||||
newModel.mergeBaseMaterials(&model(), oldToNewUniqueResourceIDs);
|
||||
newModel.mergeColorGroups(&model(), oldToNewUniqueResourceIDs);
|
||||
newModel.mergeTexture2DGroups(&model(), oldToNewUniqueResourceIDs);
|
||||
newModel.mergeCompositeMaterials(&model(), oldToNewUniqueResourceIDs);
|
||||
newModel.mergeMultiPropertyGroups(&model(), oldToNewUniqueResourceIDs);
|
||||
newModel.mergeMetaData(&model());
|
||||
|
||||
pMesh->patchMeshInformationResources(oldToNewUniqueResourceIDs);
|
||||
|
||||
newModel.setUnit(model().getUnit());
|
||||
newModel.setLanguage(model().getLanguage());
|
||||
|
||||
NMR::PModelMeshObject pMeshObject = std::make_shared<NMR::CModelMeshObject>(newModel.generateResourceID(), &newModel, pMesh);
|
||||
newModel.addResource(pMeshObject);
|
||||
|
||||
NMR::PModelBuildItem pBuildItem = std::make_shared<NMR::CModelBuildItem>(pMeshObject.get(), model().createHandle());
|
||||
newModel.addBuildItem(pBuildItem);
|
||||
|
||||
return pOutModel.release();
|
||||
}
|
||||
|
||||
IMeshObject * CModel::AddMeshObject ()
|
||||
{
|
||||
NMR::ModelResourceID NewResourceID = model().generateResourceID();
|
||||
NMR::PMesh pNewMesh = std::make_shared<NMR::CMesh>();
|
||||
NMR::PModelMeshObject pNewResource = std::make_shared<NMR::CModelMeshObject>(NewResourceID, &model(), pNewMesh);
|
||||
|
||||
model().addResource(pNewResource);
|
||||
return new CMeshObject(pNewResource);
|
||||
}
|
||||
|
||||
IComponentsObject * CModel::AddComponentsObject ()
|
||||
{
|
||||
NMR::ModelResourceID NewResourceID = model().generateResourceID();
|
||||
NMR::PModelComponentsObject pNewResource = std::make_shared<NMR::CModelComponentsObject>(NewResourceID, &model());
|
||||
|
||||
model().addResource(pNewResource);
|
||||
return new CComponentsObject(pNewResource);
|
||||
}
|
||||
|
||||
ISliceStack * CModel::AddSliceStack(const Lib3MF_double dZBottom)
|
||||
{
|
||||
NMR::ModelResourceID NewResourceID = model().generateResourceID();
|
||||
NMR::PModelSliceStack pNewResource = std::make_shared<NMR::CModelSliceStack>(NewResourceID, &model(), dZBottom);
|
||||
|
||||
model().addResource(pNewResource);
|
||||
|
||||
return new CSliceStack(pNewResource);
|
||||
}
|
||||
|
||||
|
||||
ITexture2D * CModel::AddTexture2DFromAttachment (IAttachment* pTextureAttachment)
|
||||
{
|
||||
NMR::PModelAttachment attachment = model().findModelAttachment(pTextureAttachment->GetPath());
|
||||
|
||||
NMR::PModelTexture2DResource pResource = NMR::CModelTexture2DResource::make(model().generateResourceID(), &model(), attachment);
|
||||
model().addResource(pResource);
|
||||
|
||||
return new CTexture2D(pResource);
|
||||
}
|
||||
|
||||
IBaseMaterialGroup * CModel::AddBaseMaterialGroup ()
|
||||
{
|
||||
NMR::PModelBaseMaterialResource pResource = std::make_shared<NMR::CModelBaseMaterialResource>(model().generateResourceID(), &model());
|
||||
model().addResource(pResource);
|
||||
|
||||
return new CBaseMaterialGroup(pResource);
|
||||
}
|
||||
|
||||
IColorGroup * CModel::AddColorGroup()
|
||||
{
|
||||
NMR::PModelColorGroupResource pResource = std::make_shared<NMR::CModelColorGroupResource>(model().generateResourceID(), &model());
|
||||
model().addResource(pResource);
|
||||
|
||||
return new CColorGroup(pResource);
|
||||
}
|
||||
|
||||
ITexture2DGroup * CModel::AddTexture2DGroup(ITexture2D* pTexture2DInstance)
|
||||
{
|
||||
NMR::UniqueResourceID nTexture2DID = pTexture2DInstance->GetResourceID();
|
||||
|
||||
// Find class instance
|
||||
NMR::PModelTexture2DResource pModelTexture2DObject = model().findTexture2D(nTexture2DID);
|
||||
if (pModelTexture2DObject == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_RESOURCENOTFOUND);
|
||||
|
||||
NMR::PModelTexture2DGroupResource pResource = std::make_shared<NMR::CModelTexture2DGroupResource>(model().generateResourceID(), &model(), pModelTexture2DObject);
|
||||
model().addResource(pResource);
|
||||
|
||||
return new CTexture2DGroup(pResource);
|
||||
}
|
||||
|
||||
ICompositeMaterials * CModel::AddCompositeMaterials(IBaseMaterialGroup* pBaseMaterialGroupInstance)
|
||||
{
|
||||
NMR::UniqueResourceID nBaseMaterialGroupID = pBaseMaterialGroupInstance->GetUniqueResourceID();
|
||||
NMR::PPackageResourceID pID = model().findPackageResourceID(nBaseMaterialGroupID);
|
||||
// Find class instance
|
||||
NMR::PModelBaseMaterialResource pModelBaseMaterialGroup = model().findBaseMaterial(pID);
|
||||
if (pModelBaseMaterialGroup == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_RESOURCENOTFOUND);
|
||||
|
||||
NMR::PModelCompositeMaterialsResource pResource = std::make_shared<NMR::CModelCompositeMaterialsResource>(model().generateResourceID(), &model(), pModelBaseMaterialGroup);
|
||||
model().addResource(pResource);
|
||||
|
||||
return new CCompositeMaterials(pResource);
|
||||
}
|
||||
|
||||
IMultiPropertyGroup * CModel::AddMultiPropertyGroup()
|
||||
{
|
||||
NMR::PModelMultiPropertyGroupResource pResource = std::make_shared<NMR::CModelMultiPropertyGroupResource>(model().generateResourceID(), &model());
|
||||
model().addResource(pResource);
|
||||
|
||||
return new CMultiPropertyGroup(pResource);
|
||||
}
|
||||
|
||||
IBuildItem * CModel::AddBuildItem (IObject* pObject, const sLib3MFTransform Transform)
|
||||
{
|
||||
// Get Resource ID
|
||||
NMR::UniqueResourceID nObjectID = pObject->GetResourceID();
|
||||
|
||||
// Find class instance
|
||||
NMR::CModelObject * pModelObject = model().findObject(nObjectID);
|
||||
if (pModelObject == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_RESOURCENOTFOUND);
|
||||
|
||||
// Create Build item instance
|
||||
NMR::PModelBuildItem pModelBuildItem = std::make_shared<NMR::CModelBuildItem>(pModelObject, TransformToMatrix(Transform), model().createHandle());
|
||||
model().addBuildItem(pModelBuildItem);
|
||||
|
||||
return new CBuildItem(pModelBuildItem);
|
||||
}
|
||||
|
||||
void CModel::RemoveBuildItem (IBuildItem* pBuildItemInstance)
|
||||
{
|
||||
CBuildItem* pLib3MFBuildItem = dynamic_cast<CBuildItem*> (pBuildItemInstance);
|
||||
if (!pLib3MFBuildItem)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDBUILDITEM);
|
||||
model().removeBuildItem(pLib3MFBuildItem->GetHandle(), true);
|
||||
}
|
||||
|
||||
IMetaDataGroup * CModel::GetMetaDataGroup ()
|
||||
{
|
||||
return new CMetaDataGroup(model().getMetaDataGroup());
|
||||
}
|
||||
|
||||
IAttachment * CModel::AddAttachment (const std::string & sURI, const std::string & sRelationShipType)
|
||||
{
|
||||
NMR::PImportStream pStream = std::make_shared<NMR::CImportStream_Unique_Memory>();
|
||||
|
||||
NMR::PModelAttachment pModelAttachment(model().addAttachment(sURI, sRelationShipType, pStream));
|
||||
|
||||
return new CAttachment(pModelAttachment);
|
||||
}
|
||||
|
||||
IAttachment * CModel::GetAttachment (const Lib3MF_uint32 nIndex)
|
||||
{
|
||||
NMR::PModelAttachment pAttachment = m_model->getModelAttachment(nIndex);
|
||||
return new CAttachment(pAttachment);
|
||||
}
|
||||
|
||||
IAttachment * CModel::FindAttachment (const std::string & sURI)
|
||||
{
|
||||
NMR::PModelAttachment pAttachment = m_model->findModelAttachment(sURI);
|
||||
|
||||
if (pAttachment.get() == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ATTACHMENTNOTFOUND);
|
||||
|
||||
return new CAttachment(pAttachment);
|
||||
}
|
||||
|
||||
void CModel::RemoveAttachment(IAttachment* pAttachmentInstance)
|
||||
{
|
||||
m_model->removeAttachment(pAttachmentInstance->GetPath());
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CModel::GetAttachmentCount ()
|
||||
{
|
||||
return m_model->getAttachmentCount();
|
||||
}
|
||||
|
||||
bool CModel::HasPackageThumbnailAttachment()
|
||||
{
|
||||
return m_model->getPackageThumbnail() != nullptr;
|
||||
}
|
||||
|
||||
IAttachment * CModel::CreatePackageThumbnailAttachment()
|
||||
{
|
||||
NMR::PModelAttachment pModelAttachment;
|
||||
if (HasPackageThumbnailAttachment())
|
||||
{
|
||||
pModelAttachment = m_model->getPackageThumbnail();
|
||||
}
|
||||
else {
|
||||
pModelAttachment = m_model->addPackageThumbnail();
|
||||
}
|
||||
if (pModelAttachment) {
|
||||
return new CAttachment(pModelAttachment);
|
||||
}
|
||||
else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ATTACHMENTNOTFOUND);
|
||||
}
|
||||
}
|
||||
|
||||
IAttachment * CModel::GetPackageThumbnailAttachment()
|
||||
{
|
||||
if (HasPackageThumbnailAttachment())
|
||||
{
|
||||
return new CAttachment(m_model->getPackageThumbnail());
|
||||
}
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void CModel::RemovePackageThumbnailAttachment()
|
||||
{
|
||||
m_model->removePackageThumbnail();
|
||||
}
|
||||
|
||||
void CModel::AddCustomContentType (const std::string & sExtension, const std::string & sContentType)
|
||||
{
|
||||
m_model->addCustomContentType(sExtension, sContentType);
|
||||
}
|
||||
|
||||
void CModel::RemoveCustomContentType (const std::string & sExtension)
|
||||
{
|
||||
m_model->removeCustomContentType(sExtension);
|
||||
}
|
||||
|
||||
Lib3MF::sBox CModel::GetOutbox()
|
||||
{
|
||||
NMR::NOUTBOX3 sOutbox;
|
||||
NMR::fnOutboxInitialize(sOutbox);
|
||||
|
||||
for (NMR::nfUint32 iBuildItem = 0; iBuildItem < model().getBuildItemCount(); iBuildItem++) {
|
||||
auto pBuildItem = model().getBuildItem(iBuildItem);
|
||||
pBuildItem->getObject()->extendOutbox(sOutbox, pBuildItem->getTransform());
|
||||
}
|
||||
|
||||
sBox s;
|
||||
s.m_MinCoordinate[0] = sOutbox.m_min.m_fields[0];
|
||||
s.m_MinCoordinate[1] = sOutbox.m_min.m_fields[1];
|
||||
s.m_MinCoordinate[2] = sOutbox.m_min.m_fields[2];
|
||||
|
||||
s.m_MaxCoordinate[0] = sOutbox.m_max.m_fields[0];
|
||||
s.m_MaxCoordinate[1] = sOutbox.m_max.m_fields[1];
|
||||
s.m_MaxCoordinate[2] = sOutbox.m_max.m_fields[2];
|
||||
return s;
|
||||
}
|
||||
|
||||
IKeyStore * Lib3MF::Impl::CModel::GetKeyStore() {
|
||||
return new CKeyStore(m_model);
|
||||
}
|
||||
|
||||
void Lib3MF::Impl::CModel::SetRandomNumberCallback(Lib3MF::RandomNumberCallback pTheCallback, Lib3MF_pvoid pUserData) {
|
||||
if (nullptr == pTheCallback)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
NMR::CryptoRandGenDescriptor descriptor;
|
||||
descriptor.m_pUserData = pUserData;
|
||||
descriptor.m_fnRNG = [pTheCallback](NMR::nfByte * buffer, NMR::nfUint64 size, void * userData) {
|
||||
Lib3MF_uint64 generated = 0;
|
||||
(*pTheCallback)((Lib3MF_uint64)buffer, size, userData, &generated);
|
||||
if (generated > 0)
|
||||
return generated;
|
||||
throw NMR::CNMRException(NMR_ERROR_CALCULATIONTERMINATED);
|
||||
};
|
||||
|
||||
m_model->setCryptoRandCallback(descriptor);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CMultiPropertyGroup
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_multipropertygroup.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CMultiPropertyGroup
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CMultiPropertyGroup::CMultiPropertyGroup(NMR::PModelMultiPropertyGroupResource pResource)
|
||||
: CResource(std::static_pointer_cast<NMR::CModelResource>(pResource))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
NMR::CModelMultiPropertyGroupResource& CMultiPropertyGroup::multiPropertyGroup()
|
||||
{
|
||||
NMR::CModelMultiPropertyGroupResource* pMultiPropertyGroup = dynamic_cast<NMR::CModelMultiPropertyGroupResource*>(resource().get());
|
||||
if (pMultiPropertyGroup == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDMULTIPROPERTYGROUP);
|
||||
return *pMultiPropertyGroup;
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CMultiPropertyGroup::GetCount ()
|
||||
{
|
||||
return multiPropertyGroup().getCount();
|
||||
}
|
||||
|
||||
void CMultiPropertyGroup::GetAllPropertyIDs (Lib3MF_uint64 nPropertyIDsBufferSize, Lib3MF_uint64* pPropertyIDsNeededCount, Lib3MF_uint32 * pPropertyIDsBuffer)
|
||||
{
|
||||
Lib3MF_uint32 nMultiMaterialCount = multiPropertyGroup().getCount();
|
||||
|
||||
if (pPropertyIDsNeededCount)
|
||||
*pPropertyIDsNeededCount = nMultiMaterialCount;
|
||||
|
||||
if (nPropertyIDsBufferSize >= nMultiMaterialCount && pPropertyIDsBuffer) {
|
||||
if (!multiPropertyGroup().hasResourceIndexMap()) {
|
||||
multiPropertyGroup().buildResourceIndexMap();
|
||||
}
|
||||
for (Lib3MF_uint32 i = 0; i < nMultiMaterialCount; i++) {
|
||||
DWORD nPropertyID;
|
||||
if (multiPropertyGroup().mapResourceIndexToPropertyID(i, nPropertyID)) {
|
||||
*pPropertyIDsBuffer = nPropertyID;
|
||||
}
|
||||
else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDRESOURCEINDEX);
|
||||
}
|
||||
pPropertyIDsBuffer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CMultiPropertyGroup::AddMultiProperty (const Lib3MF_uint64 nPropertyIDsBufferSize, const Lib3MF_uint32 * pPropertyIDsBuffer)
|
||||
{
|
||||
if (nPropertyIDsBufferSize > LIB3MF_MAXMULTIPROPERTIES)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ELEMENTCOUNTEXCEEDSLIMIT);
|
||||
|
||||
NMR::PModelMultiProperty multiProperty = std::make_shared<NMR::CModelMultiProperty>();
|
||||
multiProperty->resize((size_t)nPropertyIDsBufferSize);
|
||||
for (size_t i = 0; i < (size_t) nPropertyIDsBufferSize; i++) {
|
||||
(*multiProperty)[i] = pPropertyIDsBuffer[i];
|
||||
}
|
||||
return multiPropertyGroup().addMultiProperty(multiProperty);
|
||||
}
|
||||
|
||||
void CMultiPropertyGroup::SetMultiProperty (const Lib3MF_uint32 nPropertyID, const Lib3MF_uint64 nPropertyIDsBufferSize, const Lib3MF_uint32 * pPropertyIDsBuffer)
|
||||
{
|
||||
if (nPropertyIDsBufferSize > LIB3MF_MAXMULTIPROPERTIES)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ELEMENTCOUNTEXCEEDSLIMIT);
|
||||
|
||||
NMR::PModelMultiProperty multiProperty = std::make_shared<NMR::CModelMultiProperty>();
|
||||
multiProperty->resize((size_t)nPropertyIDsBufferSize);
|
||||
for (size_t i = 0; i < (size_t)nPropertyIDsBufferSize; i++) {
|
||||
(*multiProperty)[i] = pPropertyIDsBuffer[i];
|
||||
}
|
||||
multiPropertyGroup().setMultiProperty(nPropertyID, multiProperty);
|
||||
}
|
||||
|
||||
void CMultiPropertyGroup::GetMultiProperty (const Lib3MF_uint32 nPropertyID, Lib3MF_uint64 nPropertyIDsBufferSize, Lib3MF_uint64* pPropertyIDsNeededCount, Lib3MF_uint32 * pPropertyIDsBuffer)
|
||||
{
|
||||
NMR::PModelMultiProperty multiProperty = multiPropertyGroup().getMultiProperty(nPropertyID);
|
||||
|
||||
if (pPropertyIDsNeededCount) {
|
||||
*pPropertyIDsNeededCount = multiProperty->size();
|
||||
}
|
||||
|
||||
if (pPropertyIDsBuffer && nPropertyIDsBufferSize >= multiProperty->size()) {
|
||||
|
||||
if (nPropertyIDsBufferSize > LIB3MF_MAXMULTIPROPERTIES)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ELEMENTCOUNTEXCEEDSLIMIT);
|
||||
|
||||
for (size_t i = 0; i < (size_t)nPropertyIDsBufferSize; i++) {
|
||||
pPropertyIDsBuffer[i] = (*multiProperty)[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMultiPropertyGroup::RemoveMultiProperty (const Lib3MF_uint32 nPropertyID)
|
||||
{
|
||||
multiPropertyGroup().removeMultiProperty(nPropertyID);
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CMultiPropertyGroup::GetLayerCount ()
|
||||
{
|
||||
return multiPropertyGroup().getLayerCount();
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CMultiPropertyGroup::AddLayer (const sLib3MFMultiPropertyLayer TheLayer)
|
||||
{
|
||||
return multiPropertyGroup().addLayer(NMR::MODELMULTIPROPERTYLAYER{ TheLayer.m_ResourceID, NMR::eModelBlendMethod(TheLayer.m_TheBlendMethod)});
|
||||
}
|
||||
|
||||
sLib3MFMultiPropertyLayer CMultiPropertyGroup::GetLayer (const Lib3MF_uint32 nLayerIndex)
|
||||
{
|
||||
NMR::MODELMULTIPROPERTYLAYER sLayer = multiPropertyGroup().getLayer(nLayerIndex);
|
||||
sLib3MFMultiPropertyLayer outLayer;
|
||||
outLayer.m_ResourceID = sLayer.m_nUniqueResourceID;
|
||||
outLayer.m_TheBlendMethod = (eLib3MFBlendMethod)sLayer.m_nMethod;
|
||||
return outLayer;
|
||||
}
|
||||
|
||||
void CMultiPropertyGroup::RemoveLayer (const Lib3MF_uint32 nLayerIndex)
|
||||
{
|
||||
multiPropertyGroup().removeLayer(nLayerIndex);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CMultiPropertyGroupIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_multipropertygroupiterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_multipropertygroup.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CMultiPropertyGroupIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
IMultiPropertyGroup * CMultiPropertyGroupIterator::GetCurrentMultiPropertyGroup ()
|
||||
{
|
||||
return new CMultiPropertyGroup(std::dynamic_pointer_cast<NMR::CModelMultiPropertyGroupResource>(GetCurrentResource()));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CObject
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_object.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
#include "lib3mf_meshobject.hpp"
|
||||
#include "lib3mf_componentsobject.hpp"
|
||||
#include "lib3mf_metadatagroup.hpp"
|
||||
#include "lib3mf_slicestack.hpp"
|
||||
#include "lib3mf_attachment.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "Model/Classes/NMR_ModelMeshObject.h"
|
||||
#include "Model/Classes/NMR_ModelComponentsObject.h"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CObject
|
||||
**************************************************************************************************************************/
|
||||
|
||||
NMR::CModelObject* CObject::object()
|
||||
{
|
||||
NMR::CModelObject* pObject = dynamic_cast<NMR::CModelObject*>(resource().get());
|
||||
if (pObject == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDOBJECT);
|
||||
return pObject;
|
||||
}
|
||||
|
||||
IObject* CObject::fnCreateObjectFromModelResource(NMR::PModelResource pResource, bool bFailIfUnkownClass) {
|
||||
|
||||
if (!pResource.get())
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
NMR::CModelMeshObject * pMeshObject = dynamic_cast<NMR::CModelMeshObject *> (pResource.get());
|
||||
if (pMeshObject) {
|
||||
return new CMeshObject(pResource);
|
||||
}
|
||||
|
||||
NMR::CModelComponentsObject * pComponentsResource = dynamic_cast<NMR::CModelComponentsObject *> (pResource.get());
|
||||
if (pComponentsResource) {
|
||||
return new CComponentsObject(pResource);
|
||||
}
|
||||
|
||||
if (bFailIfUnkownClass)
|
||||
throw ELib3MFInterfaceException(NMR_ERROR_UNKNOWNMODELRESOURCE);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CObject::CObject(NMR::PModelResource pResource)
|
||||
:CResource(pResource)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eLib3MFObjectType CObject::GetType ()
|
||||
{
|
||||
return eLib3MFObjectType(object()->getObjectType());
|
||||
}
|
||||
|
||||
void CObject::SetType (const eLib3MFObjectType eObjectType)
|
||||
{
|
||||
object()->setObjectType(NMR::eModelObjectType(eObjectType));
|
||||
}
|
||||
|
||||
std::string CObject::GetName ()
|
||||
{
|
||||
return object()->getName();
|
||||
}
|
||||
|
||||
void CObject::SetName (const std::string & sName)
|
||||
{
|
||||
object()->setName(sName);
|
||||
}
|
||||
|
||||
std::string CObject::GetPartNumber ()
|
||||
{
|
||||
return object()->getPartNumber();
|
||||
}
|
||||
|
||||
void CObject::SetPartNumber (const std::string & sPartNumber)
|
||||
{
|
||||
object()->setPartNumber(sPartNumber);
|
||||
}
|
||||
|
||||
bool CObject::IsMeshObject ()
|
||||
{
|
||||
// overwritten by child class
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_SHOULDNOTBECALLED);
|
||||
}
|
||||
|
||||
bool CObject::IsComponentsObject ()
|
||||
{
|
||||
// overwritten by child class
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_SHOULDNOTBECALLED);
|
||||
}
|
||||
|
||||
IMeshObject * CObject::AsMeshObject()
|
||||
{
|
||||
if (dynamic_cast<NMR::CModelMeshObject*>(resource().get()))
|
||||
{
|
||||
return new CMeshObject(resource());
|
||||
}
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCAST);
|
||||
}
|
||||
|
||||
IComponentsObject * CObject::AsComponentsObject()
|
||||
{
|
||||
if (dynamic_cast<NMR::CModelComponentsObject*>(resource().get()))
|
||||
{
|
||||
return new CComponentsObject(resource());
|
||||
}
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCAST);
|
||||
}
|
||||
|
||||
bool CObject::IsValid ()
|
||||
{
|
||||
// Implemented by base class
|
||||
throw ELib3MFInterfaceException (LIB3MF_ERROR_SHOULDNOTBECALLED);
|
||||
}
|
||||
|
||||
void CObject::SetAttachmentAsThumbnail(IAttachment* pAttachment)
|
||||
{
|
||||
auto pModelAttachment = object()->getModel()->findModelAttachment(pAttachment->GetPath());
|
||||
if (!pModelAttachment) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ATTACHMENTNOTFOUND);
|
||||
}
|
||||
object()->setThumbnailAttachment(pModelAttachment, true);
|
||||
}
|
||||
|
||||
IAttachment * CObject::GetThumbnailAttachment()
|
||||
{
|
||||
if (object()->getThumbnailAttachment()) {
|
||||
return new CAttachment(object()->getThumbnailAttachment());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CObject::ClearThumbnailAttachment()
|
||||
{
|
||||
object()->clearThumbnailAttachment();
|
||||
}
|
||||
|
||||
|
||||
IMetaDataGroup * CObject::GetMetaDataGroup ()
|
||||
{
|
||||
return new CMetaDataGroup(object()->metaDataGroup());
|
||||
}
|
||||
|
||||
std::string CObject::GetUUID(bool & bHasUUID)
|
||||
{
|
||||
NMR::PUUID pUUID = object()->uuid();
|
||||
bHasUUID = (pUUID.get() != nullptr);
|
||||
if (bHasUUID)
|
||||
return pUUID->toString();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
void CObject::SetUUID(const std::string & sUUID)
|
||||
{
|
||||
NMR::PUUID pUUID = std::make_shared<NMR::CUUID>(sUUID);
|
||||
object()->setUUID(pUUID);
|
||||
}
|
||||
|
||||
void CObject::SetSlicesMeshResolution(const eLib3MFSlicesMeshResolution eMeshResolution)
|
||||
{
|
||||
object()->setSlicesMeshResolution(NMR::eModelSlicesMeshResolution(eMeshResolution));
|
||||
}
|
||||
|
||||
eLib3MFSlicesMeshResolution CObject::GetSlicesMeshResolution()
|
||||
{
|
||||
return eLib3MFSlicesMeshResolution(object()->slicesMeshResolution());
|
||||
}
|
||||
|
||||
bool CObject::HasSlices(const bool bRecursive)
|
||||
{
|
||||
return object()->hasSlices(bRecursive);
|
||||
}
|
||||
|
||||
void CObject::ClearSliceStack()
|
||||
{
|
||||
object()->assignSliceStack(nullptr);
|
||||
}
|
||||
|
||||
ISliceStack * CObject::GetSliceStack()
|
||||
{
|
||||
NMR::PModelSliceStack pSliceStackResource = object()->getSliceStack();
|
||||
if (pSliceStackResource)
|
||||
return new CSliceStack(pSliceStackResource);
|
||||
else
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDSLICESTACKRESOURCE);
|
||||
}
|
||||
|
||||
void CObject::AssignSliceStack(ISliceStack* pSliceStackInstance)
|
||||
{
|
||||
NMR::ModelResourceID nID = pSliceStackInstance->GetResourceID();
|
||||
std::shared_ptr<IPackagePart> pPackagePart(pSliceStackInstance->PackagePart());
|
||||
std::string sPath = pPackagePart->GetPath();
|
||||
|
||||
NMR::PModelSliceStack pSliceStackResource = std::dynamic_pointer_cast<NMR::CModelSliceStack>
|
||||
( object()->getModel()->findResource(sPath, nID) );
|
||||
if (!pSliceStackResource)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDSLICESTACKRESOURCE);
|
||||
|
||||
object()->assignSliceStack(pSliceStackResource);
|
||||
}
|
||||
|
||||
Lib3MF::sBox CObject::GetOutbox()
|
||||
{
|
||||
NMR::NOUTBOX3 oOutbox;
|
||||
NMR::fnOutboxInitialize(oOutbox);
|
||||
|
||||
object()->extendOutbox(oOutbox, NMR::fnMATRIX3_identity());
|
||||
|
||||
sBox s;
|
||||
s.m_MinCoordinate[0] = oOutbox.m_min.m_fields[0];
|
||||
s.m_MinCoordinate[1] = oOutbox.m_min.m_fields[1];
|
||||
s.m_MinCoordinate[2] = oOutbox.m_min.m_fields[2];
|
||||
|
||||
s.m_MaxCoordinate[0] = oOutbox.m_max.m_fields[0];
|
||||
s.m_MaxCoordinate[1] = oOutbox.m_max.m_fields[1];
|
||||
s.m_MaxCoordinate[2] = oOutbox.m_max.m_fields[2];
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CObjectIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_objectiterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_object.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CObjectIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
IObject * CObjectIterator::GetCurrentObject ()
|
||||
{
|
||||
return CObject::fnCreateObjectFromModelResource(GetCurrentResource(), true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CPackagePart
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_packagepart.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
#include "Model/Classes/NMR_PackageResourceID.h"
|
||||
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CPackagePart
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CPackagePart::CPackagePart(NMR::PPackageModelPath pPath)
|
||||
: m_pPath(pPath)
|
||||
{
|
||||
if (!pPath.get())
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
|
||||
std::string CPackagePart::GetPath()
|
||||
{
|
||||
return m_pPath->getPath();
|
||||
}
|
||||
|
||||
void CPackagePart::SetPath(const std::string & sPath)
|
||||
{
|
||||
m_pPath->setPath(sPath);
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CReader
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_reader.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
#include "lib3mf_accessright.hpp"
|
||||
#include "lib3mf_contentencryptionparams.hpp"
|
||||
#include "Common/Platform/NMR_Platform.h"
|
||||
#include "Common/Platform/NMR_ImportStream_Shared_Memory.h"
|
||||
#include "Common/Platform/NMR_ImportStream_Callback.h"
|
||||
#include "Common/NMR_SecureContentTypes.h"
|
||||
#include "Common/NMR_SecureContext.h"
|
||||
#include "Model/Classes/NMR_KeyStore.h"
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CReader
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CReader::CReader(std::string sReaderClass, NMR::PModel model)
|
||||
{
|
||||
m_pReader = nullptr;
|
||||
|
||||
// Create specified writer instance
|
||||
if (sReaderClass.compare("3mf") == 0) {
|
||||
m_pReader = std::make_shared<NMR::CModelReader_3MF_Native>(model);
|
||||
|
||||
}
|
||||
else if (sReaderClass.compare("stl") == 0) {
|
||||
m_pReader = std::make_shared<NMR::CModelReader_STL>(model);
|
||||
}
|
||||
|
||||
if (!m_pReader)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_READERCLASSUNKNOWN);
|
||||
}
|
||||
|
||||
NMR::CModelReader& CReader::reader()
|
||||
{
|
||||
return *m_pReader;
|
||||
}
|
||||
|
||||
void CReader::ReadFromFile (const std::string & sFilename)
|
||||
{
|
||||
NMR::PImportStream pImportStream = NMR::fnCreateImportStreamInstance(sFilename.c_str());
|
||||
|
||||
try {
|
||||
reader().readStream(pImportStream);
|
||||
}
|
||||
catch (NMR::CNMRException&e) {
|
||||
if (e.getErrorCode() == NMR_USERABORTED) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
}
|
||||
else throw e;
|
||||
}
|
||||
}
|
||||
|
||||
void CReader::ReadFromBuffer (const Lib3MF_uint64 nBufferBufferSize, const Lib3MF_uint8 * pBufferBuffer)
|
||||
{
|
||||
NMR::PImportStream pImportStream = std::make_shared<NMR::CImportStream_Shared_Memory>(pBufferBuffer, nBufferBufferSize);
|
||||
|
||||
try {
|
||||
reader().readStream(pImportStream);
|
||||
}
|
||||
catch (NMR::CNMRException&e) {
|
||||
if (e.getErrorCode() == NMR_USERABORTED) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
}
|
||||
else throw e;
|
||||
}
|
||||
}
|
||||
|
||||
void CReader::ReadFromCallback(const Lib3MFReadCallback pTheReadCallback, const Lib3MF_uint64 nStreamSize, const Lib3MFSeekCallback pTheSeekCallback, const Lib3MF_pvoid pUserData)
|
||||
{
|
||||
|
||||
NMR::ImportStream_ReadCallbackType lambdaReadCallback =
|
||||
[pTheReadCallback](NMR::nfByte* pData, NMR::nfUint64 cbBytes, void* pUserData)
|
||||
{
|
||||
(*pTheReadCallback)(reinterpret_cast<Lib3MF_uint64>(pData), cbBytes, pUserData);
|
||||
return 0;
|
||||
};
|
||||
|
||||
NMR::ImportStream_SeekCallbackType lambdaSeekCallback =
|
||||
[pTheSeekCallback](NMR::nfUint64 nPosition, void* pUserData)
|
||||
{
|
||||
(*pTheSeekCallback)(nPosition, pUserData);
|
||||
return 0;
|
||||
};
|
||||
|
||||
NMR::PImportStream pImportStream = std::make_shared<NMR::CImportStream_Callback>(
|
||||
lambdaReadCallback, lambdaSeekCallback,
|
||||
pUserData, nStreamSize);
|
||||
try {
|
||||
reader().readStream(pImportStream);
|
||||
}
|
||||
catch (NMR::CNMRException&e) {
|
||||
if (e.getErrorCode() == NMR_USERABORTED) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
}
|
||||
else throw e;
|
||||
}
|
||||
}
|
||||
|
||||
void CReader::SetProgressCallback(const Lib3MFProgressCallback pProgressCallback, const Lib3MF_pvoid pUserData)
|
||||
{
|
||||
NMR::Lib3MFProgressCallback lambdaCallback =
|
||||
[pProgressCallback](int progressStep, NMR::ProgressIdentifier identifier, void* pUserData)
|
||||
{
|
||||
bool ret;
|
||||
(*pProgressCallback)(&ret, progressStep / 100.0f, eLib3MFProgressIdentifier(identifier), pUserData);
|
||||
return ret;
|
||||
};
|
||||
m_pReader->SetProgressCallback(lambdaCallback, pUserData);
|
||||
}
|
||||
|
||||
void CReader::AddRelationToRead (const std::string & sRelationShipType)
|
||||
{
|
||||
reader().addRelationToRead(sRelationShipType);
|
||||
}
|
||||
|
||||
void CReader::RemoveRelationToRead (const std::string & sRelationShipType)
|
||||
{
|
||||
reader().removeRelationToRead(sRelationShipType);
|
||||
}
|
||||
|
||||
void CReader::SetStrictModeActive (const bool bStrictModeActive)
|
||||
{
|
||||
if (bStrictModeActive)
|
||||
reader().warnings()->setCriticalWarningLevel(NMR::mrwInvalidOptionalValue);
|
||||
else
|
||||
reader().warnings()->setCriticalWarningLevel(NMR::mrwFatal);
|
||||
}
|
||||
|
||||
bool CReader::GetStrictModeActive ()
|
||||
{
|
||||
return reader().warnings()->getCriticalWarningLevel() == NMR::mrwInvalidOptionalValue;
|
||||
}
|
||||
|
||||
std::string CReader::GetWarning (const Lib3MF_uint32 nIndex, Lib3MF_uint32 & nErrorCode)
|
||||
{
|
||||
auto warning = reader().warnings()->getWarning(nIndex);
|
||||
nErrorCode = warning->getErrorCode();
|
||||
return warning->getMessage();
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CReader::GetWarningCount ()
|
||||
{
|
||||
return reader().warnings()->getWarningCount();
|
||||
}
|
||||
|
||||
void Lib3MF::Impl::CReader::AddKeyWrappingCallback(const std::string &sConsumerID, const Lib3MF::KeyWrappingCallback pTheCallback, const Lib3MF_pvoid pUserData) {
|
||||
NMR::KeyWrappingDescriptor descriptor;
|
||||
descriptor.m_sKekDecryptData.m_pUserData = pUserData;
|
||||
descriptor.m_fnWrap =
|
||||
[this, pTheCallback](
|
||||
std::vector<NMR::nfByte> const & cipher,
|
||||
std::vector<NMR::nfByte> & plain,
|
||||
NMR::KeyWrappingContext & ctx) {
|
||||
|
||||
std::shared_ptr<IAccessRight> pAccessRight = std::make_shared<CAccessRight>(ctx.m_pAccessRight);
|
||||
IBase * pBaseEntity(nullptr);
|
||||
pBaseEntity = pAccessRight.get();
|
||||
Lib3MF_AccessRight entityHandle = pBaseEntity;
|
||||
|
||||
//figure out the size of the key.
|
||||
Lib3MF_uint64 needed = 0;
|
||||
Lib3MF_uint64 result = 0;
|
||||
(*pTheCallback)(entityHandle, cipher.size(), cipher.data(),
|
||||
0, &needed, nullptr, ctx.m_pUserData, &result);
|
||||
if (result == 0)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
|
||||
plain.resize(needed, 0);
|
||||
|
||||
result = 0;
|
||||
(*pTheCallback)(entityHandle, cipher.size(), cipher.data(),
|
||||
plain.size(), nullptr, plain.data(), ctx.m_pUserData, &result);
|
||||
if (result == 0)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
return (NMR::nfUint64)result;
|
||||
};
|
||||
reader().secureContext()->addKekCtx(sConsumerID, descriptor);
|
||||
}
|
||||
void Lib3MF::Impl::CReader::SetContentEncryptionCallback(const Lib3MF::ContentEncryptionCallback pTheCallback, const Lib3MF_pvoid pUserData) {
|
||||
NMR::ContentEncryptionDescriptor descriptor;
|
||||
descriptor.m_sDekDecryptData.m_pUserData = pUserData;
|
||||
descriptor.m_fnCrypt = [this, pTheCallback](NMR::nfUint64 size, NMR::nfByte const * cipher, NMR::nfByte * plain, NMR::ContentEncryptionContext & ctx) {
|
||||
std::shared_ptr<CContentEncryptionParams> pCekParams = std::make_shared<CContentEncryptionParams>(ctx.m_sParams);
|
||||
IBase * pBaseEntity(nullptr);
|
||||
pBaseEntity = pCekParams.get();
|
||||
Lib3MF_ContentEncryptionParams entityHandle = pBaseEntity;
|
||||
Lib3MF_uint64 result = 0;
|
||||
(*pTheCallback)(entityHandle, (Lib3MF_uint64)size, cipher, (Lib3MF_uint64)size, nullptr, plain, ctx.m_pUserData, &result);
|
||||
if (result == 0)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
return (NMR::nfUint64)result;
|
||||
};
|
||||
reader().secureContext()->setDekCtx(descriptor);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CResource
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_resource.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_packagepart.hpp"
|
||||
#include "Model/Classes/NMR_ModelObject.h"
|
||||
#include "lib3mf_object.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CResource
|
||||
**************************************************************************************************************************/
|
||||
|
||||
|
||||
NMR::PModelResource CResource::resource()
|
||||
{
|
||||
if (m_pResource.get()==nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDOBJECT);
|
||||
|
||||
return m_pResource;
|
||||
}
|
||||
|
||||
CResource::CResource(NMR::PModelResource pResource)
|
||||
{
|
||||
if (pResource.get() == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDMODELRESOURCE);
|
||||
m_pResource = pResource;
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CResource::GetResourceID()
|
||||
{
|
||||
return m_pResource->getPackageResourceID()->getUniqueID();
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CResource::GetUniqueResourceID()
|
||||
{
|
||||
return m_pResource->getPackageResourceID()->getUniqueID();
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CResource::GetModelResourceID()
|
||||
{
|
||||
return m_pResource->getPackageResourceID()->getModelResourceID();
|
||||
}
|
||||
|
||||
IObject * CResource::AsObject()
|
||||
{
|
||||
if (dynamic_cast<NMR::CModelObject*>(m_pResource.get()))
|
||||
{
|
||||
return new CObject(m_pResource);
|
||||
}
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDCAST);
|
||||
}
|
||||
|
||||
IPackagePart * CResource::PackagePart()
|
||||
{
|
||||
return new CPackagePart(m_pResource->getPackageResourceID()->getPackageModelPath());
|
||||
}
|
||||
|
||||
void CResource::SetPackagePart(IPackagePart* pPackagePart)
|
||||
{
|
||||
std::string sPath = pPackagePart->GetPath();
|
||||
NMR::ModelResourceID nID = m_pResource->getPackageResourceID()->getModelResourceID();
|
||||
NMR::PPackageResourceID pTargetPackageResourceID = m_pResource->getModel()->findPackageResourceID(sPath, nID);
|
||||
if (pTargetPackageResourceID) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDMODELRESOURCE);
|
||||
}
|
||||
NMR::PPackageResourceID pIDOld = m_pResource->getPackageResourceID();
|
||||
NMR::PPackageResourceID pID = m_pResource->getModel()->generatePackageResourceID(sPath, nID);
|
||||
m_pResource->setPackageResourceID(pID);
|
||||
|
||||
m_pResource->getModel()->removePackageResourceID(pIDOld);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "lib3mf_resourcedata.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
#include "lib3mf_consumer.hpp"
|
||||
#include "lib3mf_packagepart.hpp"
|
||||
#include "lib3mf_utils.hpp"
|
||||
|
||||
namespace Lib3MF {
|
||||
namespace Impl {
|
||||
Lib3MF::Impl::CResourceData::CResourceData(NMR::PKeyStoreResourceData resourceData)
|
||||
:m_pResourceData(resourceData)
|
||||
{
|
||||
if (!resourceData)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
|
||||
Lib3MF::eEncryptionAlgorithm Lib3MF::Impl::CResourceData::GetEncryptionAlgorithm() {
|
||||
NMR::eKeyStoreEncryptAlgorithm ea = m_pResourceData->getEncryptionAlgorithm();
|
||||
return static_cast<eEncryptionAlgorithm>(ea);
|
||||
}
|
||||
|
||||
Lib3MF::eCompression Lib3MF::Impl::CResourceData::GetCompression() {
|
||||
return translateCompression(m_pResourceData->isCompressed());
|
||||
}
|
||||
|
||||
IPackagePart * CResourceData::GetPath() {
|
||||
return new CPackagePart(m_pResourceData->packagePath());
|
||||
}
|
||||
|
||||
void CResourceData::GetAdditionalAuthenticationData(Lib3MF_uint64 nByteDataBufferSize, Lib3MF_uint64 * pByteDataNeededCount, Lib3MF_uint8 * pByteDataBuffer) {
|
||||
std::vector<NMR::nfByte> const & aad = m_pResourceData->getAddAuthData();
|
||||
if (nByteDataBufferSize < aad.size()) {
|
||||
*pByteDataNeededCount = aad.size();
|
||||
} else {
|
||||
std::copy(aad.begin(), aad.end(), pByteDataBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
|
||||
#include "lib3mf_resourcedatagroup.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
#include "lib3mf_consumer.hpp"
|
||||
#include "lib3mf_accessright.hpp"
|
||||
|
||||
#include "Model/Classes/NMR_KeyStoreFactory.h"
|
||||
namespace Lib3MF {
|
||||
namespace Impl {
|
||||
CResourceDataGroup::CResourceDataGroup(NMR::PKeyStoreResourceDataGroup const & dg)
|
||||
: m_pDataGroup(dg)
|
||||
{
|
||||
if (!dg)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
}
|
||||
|
||||
IAccessRight * CResourceDataGroup::AddAccessRight(IConsumer * pConsumer, const Lib3MF::eWrappingAlgorithm eWrappingAlgorithm, const Lib3MF::eMgfAlgorithm eMgfAlgorithm, const Lib3MF::eDigestMethod eDigestMethod) {
|
||||
CConsumer * c = dynamic_cast<CConsumer *>(pConsumer);
|
||||
if (nullptr == c)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
NMR::PKeyStoreAccessRight ar = NMR::CKeyStoreFactory::makeAccessRight(
|
||||
c->consumer(),
|
||||
(NMR::eKeyStoreWrapAlgorithm)eWrappingAlgorithm,
|
||||
(NMR::eKeyStoreMaskGenerationFunction)eMgfAlgorithm,
|
||||
(NMR::eKeyStoreMessageDigest)eDigestMethod);
|
||||
m_pDataGroup->addAccessRight(ar);
|
||||
return new CAccessRight(ar);
|
||||
}
|
||||
|
||||
IAccessRight * CResourceDataGroup::FindAccessRightByConsumer(IConsumer * pConsumerInstance) {
|
||||
NMR::PKeyStoreAccessRight ar = m_pDataGroup->findAccessRightByConsumerID(pConsumerInstance->GetConsumerID());
|
||||
if (!ar)
|
||||
return nullptr;
|
||||
return new CAccessRight(ar);
|
||||
}
|
||||
|
||||
void CResourceDataGroup::RemoveAccessRight(IConsumer * pConsumerInstance) {
|
||||
m_pDataGroup->removeAccessRight(pConsumerInstance->GetConsumerID());
|
||||
}
|
||||
|
||||
std::string CResourceDataGroup::GetKeyUUID() {
|
||||
return m_pDataGroup->getKeyUUID()->toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CResourceIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_resource.hpp"
|
||||
#include "lib3mf_resourceiterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CResourceIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CResourceIterator::CResourceIterator()
|
||||
{
|
||||
m_nCurrentIndex = -1;
|
||||
}
|
||||
|
||||
void CResourceIterator::addResource(NMR::PModelResource pResource)
|
||||
{
|
||||
if (pResource.get() == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDPARAM);
|
||||
|
||||
m_pResources.push_back(pResource);
|
||||
}
|
||||
|
||||
bool CResourceIterator::MoveNext ()
|
||||
{
|
||||
// Get Resource Count
|
||||
Lib3MF_int32 nBuildItemCount = (Lib3MF_int32)m_pResources.size();
|
||||
m_nCurrentIndex++;
|
||||
|
||||
// Check new Index
|
||||
if (m_nCurrentIndex >= nBuildItemCount) {
|
||||
m_nCurrentIndex = nBuildItemCount;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool CResourceIterator::MovePrevious ()
|
||||
{
|
||||
// Get Resource Count
|
||||
m_nCurrentIndex--;
|
||||
|
||||
// Check new Index
|
||||
if (m_nCurrentIndex <= -1) {
|
||||
m_nCurrentIndex = -1;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
NMR::PModelResource CResourceIterator::GetCurrentResource()
|
||||
{
|
||||
// Get Resource Count
|
||||
Lib3MF_int32 nBuildItemCount = (Lib3MF_int32)m_pResources.size();
|
||||
if ((m_nCurrentIndex < 0) || (m_nCurrentIndex >= nBuildItemCount))
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_ITERATORINVALIDINDEX);
|
||||
|
||||
return m_pResources[m_nCurrentIndex];
|
||||
}
|
||||
|
||||
IResource * CResourceIterator::GetCurrent ()
|
||||
{
|
||||
// Create specific API class
|
||||
return new CResource(GetCurrentResource());
|
||||
}
|
||||
|
||||
IResourceIterator * CResourceIterator::Clone ()
|
||||
{
|
||||
auto pResources = std::unique_ptr<CResourceIterator>(new CResourceIterator());
|
||||
|
||||
for (auto iIterator = m_pResources.begin(); iIterator != m_pResources.end(); iIterator++)
|
||||
pResources->addResource(*iIterator);
|
||||
|
||||
return pResources.release();
|
||||
}
|
||||
|
||||
Lib3MF_uint64 CResourceIterator::Count()
|
||||
{
|
||||
return m_pResources.size();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CSlice
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_slice.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CSlice
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CSlice::CSlice(NMR::PSlice pSlice)
|
||||
:m_pSlice(pSlice)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSlice::SetVertices (const Lib3MF_uint64 nVerticesBufferSize, const sLib3MFPosition2D * pVerticesBuffer)
|
||||
{
|
||||
m_pSlice->Clear();
|
||||
for (Lib3MF_uint64 index = 0; index < nVerticesBufferSize; index++) {
|
||||
m_pSlice->addVertex(pVerticesBuffer->m_Coordinates[0], pVerticesBuffer->m_Coordinates[1]);
|
||||
pVerticesBuffer++;
|
||||
}
|
||||
}
|
||||
|
||||
void CSlice::GetVertices (Lib3MF_uint64 nVerticesBufferSize, Lib3MF_uint64* pVerticesNeededCount, sLib3MFPosition2D * pVerticesBuffer)
|
||||
{
|
||||
Lib3MF_uint64 vertexCount = m_pSlice->getVertexCount();
|
||||
if (pVerticesNeededCount)
|
||||
*pVerticesNeededCount = vertexCount;
|
||||
|
||||
if (nVerticesBufferSize >= vertexCount && pVerticesBuffer)
|
||||
{
|
||||
for (Lib3MF_uint32 i = 0; i < vertexCount; i++)
|
||||
{
|
||||
const NMR::SLICENODE* node = m_pSlice->getNode(i);
|
||||
pVerticesBuffer[i].m_Coordinates[0] = node->m_position.m_fields[0];
|
||||
pVerticesBuffer[i].m_Coordinates[1] = node->m_position.m_fields[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Lib3MF_uint64 CSlice::GetVertexCount ()
|
||||
{
|
||||
return m_pSlice->getVertexCount();
|
||||
}
|
||||
|
||||
Lib3MF_uint64 CSlice::AddPolygon(const Lib3MF_uint64 nIndicesBufferSize, const Lib3MF_uint32 * pIndicesBuffer)
|
||||
{
|
||||
Lib3MF_uint32 index = m_pSlice->beginPolygon();
|
||||
SetPolygonIndices(index, nIndicesBufferSize, pIndicesBuffer);
|
||||
return index;
|
||||
}
|
||||
|
||||
Lib3MF_uint64 CSlice::GetPolygonCount ()
|
||||
{
|
||||
return m_pSlice->getPolygonCount();
|
||||
}
|
||||
|
||||
void CSlice::SetPolygonIndices (const Lib3MF_uint64 nIndex, const Lib3MF_uint64 nIndicesBufferSize, const Lib3MF_uint32 * pIndicesBuffer)
|
||||
{
|
||||
m_pSlice->clearPolygon(NMR::nfUint32(nIndex));
|
||||
|
||||
for (Lib3MF_uint64 i=0; i< nIndicesBufferSize; i++)
|
||||
m_pSlice->addPolygonIndex(NMR::nfUint32(nIndex), pIndicesBuffer[i]);
|
||||
}
|
||||
|
||||
void CSlice::GetPolygonIndices (const Lib3MF_uint64 nIndex, Lib3MF_uint64 nIndicesBufferSize, Lib3MF_uint64* pIndicesNeededCount, Lib3MF_uint32 * pIndicesBuffer)
|
||||
{
|
||||
Lib3MF_uint64 indexCount = m_pSlice->getPolygonIndexCount(NMR::nfUint32(nIndex));
|
||||
if (pIndicesNeededCount)
|
||||
*pIndicesNeededCount = indexCount;
|
||||
|
||||
if (nIndicesBufferSize >= indexCount && pIndicesBuffer)
|
||||
{
|
||||
for (Lib3MF_uint32 i = 0; i < indexCount; i++)
|
||||
{
|
||||
pIndicesBuffer[i] = m_pSlice->getPolygonIndex(NMR::nfUint32(nIndex), i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Lib3MF_uint64 CSlice::GetPolygonIndexCount (const Lib3MF_uint64 nIndex)
|
||||
{
|
||||
return m_pSlice->getPolygonIndexCount(NMR::nfUint32(nIndex));
|
||||
}
|
||||
|
||||
double CSlice::GetZTop()
|
||||
{
|
||||
return m_pSlice->getTopZ();
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CSliceStack
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_slicestack.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
#include "lib3mf_slice.hpp"
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CSliceStack
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CSliceStack::CSliceStack(NMR::PModelSliceStack pSliceStack):
|
||||
CResource(pSliceStack)
|
||||
{
|
||||
}
|
||||
|
||||
NMR::PModelSliceStack CSliceStack::sliceStack()
|
||||
{
|
||||
return std::dynamic_pointer_cast<NMR::CModelSliceStack>(resource());
|
||||
}
|
||||
|
||||
double CSliceStack::GetBottomZ()
|
||||
{
|
||||
return sliceStack()->getZBottom();
|
||||
}
|
||||
|
||||
Lib3MF_uint64 CSliceStack::GetSliceCount ()
|
||||
{
|
||||
return sliceStack()->getSliceCount();
|
||||
}
|
||||
|
||||
ISlice * CSliceStack::GetSlice (const Lib3MF_uint64 nSliceIndex)
|
||||
{
|
||||
NMR::PSlice pSlice = sliceStack()->getSlice(Lib3MF_uint32(nSliceIndex));
|
||||
return new CSlice(pSlice);
|
||||
}
|
||||
|
||||
ISlice * CSliceStack::AddSlice (const double fZTop)
|
||||
{
|
||||
NMR::PSlice pSlice = sliceStack()->AddSlice(fZTop);
|
||||
return new CSlice(pSlice);
|
||||
}
|
||||
|
||||
Lib3MF_uint64 CSliceStack::GetSliceRefCount()
|
||||
{
|
||||
return sliceStack()->getSliceRefCount();
|
||||
}
|
||||
|
||||
void CSliceStack::AddSliceStackReference(ISliceStack* pTheSliceStack)
|
||||
{
|
||||
NMR::ModelResourceID nID = pTheSliceStack->GetResourceID();
|
||||
|
||||
std::shared_ptr<IPackagePart> pPackagePart(pTheSliceStack->PackagePart());
|
||||
std::string sPath = pPackagePart->GetPath();
|
||||
|
||||
NMR::PModelResource pResource = sliceStack()->getModel()->findResource(sPath, nID);
|
||||
NMR::PModelSliceStack pModelSliceStack = std::dynamic_pointer_cast<NMR::CModelSliceStack>(pResource);
|
||||
if (!pModelSliceStack)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDSLICESTACKRESOURCE);
|
||||
|
||||
sliceStack()->AddSliceRef(pModelSliceStack);
|
||||
}
|
||||
|
||||
ISliceStack * CSliceStack::GetSliceStackReference(const Lib3MF_uint64 nSliceRefIndex)
|
||||
{
|
||||
NMR::PModelSliceStack pModelSliceStack = sliceStack()->getSliceRef(Lib3MF_uint32(nSliceRefIndex));
|
||||
return new CSliceStack(pModelSliceStack);
|
||||
}
|
||||
|
||||
void CSliceStack::CollapseSliceReferences()
|
||||
{
|
||||
sliceStack()->CollapseSliceReferences();
|
||||
}
|
||||
|
||||
void CSliceStack::SetOwnPath(const std::string & sPath)
|
||||
{
|
||||
sliceStack()->SetOwnPath(sPath);
|
||||
}
|
||||
|
||||
std::string CSliceStack::GetOwnPath()
|
||||
{
|
||||
return sliceStack()->OwnPath();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CSliceStackIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_slicestackiterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_slicestack.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CSliceStackIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
ISliceStack * CSliceStackIterator::GetCurrentSliceStack ()
|
||||
{
|
||||
return new CSliceStack(std::dynamic_pointer_cast<NMR::CModelSliceStack>(GetCurrentResource()));
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CTexture2D
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_texture2d.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
#include "lib3mf_attachment.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CTexture2D
|
||||
**************************************************************************************************************************/
|
||||
|
||||
|
||||
CTexture2D::CTexture2D(NMR::PModelTexture2DResource pResource)
|
||||
:CResource(pResource)
|
||||
{
|
||||
}
|
||||
|
||||
NMR::PModelTexture2DResource CTexture2D::texture()
|
||||
{
|
||||
NMR::PModelTexture2DResource pTexture = std::dynamic_pointer_cast<NMR::CModelTexture2DResource>(resource());
|
||||
if (!pTexture)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDTEXTURERESOURCE);
|
||||
return pTexture;
|
||||
}
|
||||
|
||||
|
||||
IAttachment * CTexture2D::GetAttachment ()
|
||||
{
|
||||
return new CAttachment(texture()->getAttachment());
|
||||
}
|
||||
|
||||
void CTexture2D::SetAttachment (IAttachment* pAttachment)
|
||||
{
|
||||
NMR::PModelAttachment attachment = texture()->getModel()->findModelAttachment(pAttachment->GetPath());
|
||||
texture()->setAttachment(attachment);
|
||||
}
|
||||
|
||||
eLib3MFTextureType CTexture2D::GetContentType ()
|
||||
{
|
||||
return (eLib3MFTextureType)(texture()->getContentType());
|
||||
}
|
||||
|
||||
void CTexture2D::SetContentType (const eLib3MFTextureType eContentType)
|
||||
{
|
||||
texture()->setContentType(NMR::eModelTexture2DType(eContentType));
|
||||
}
|
||||
|
||||
void CTexture2D::GetTileStyleUV (eLib3MFTextureTileStyle & eTileStyleU, eLib3MFTextureTileStyle & eTileStyleV)
|
||||
{
|
||||
eTileStyleU = eLib3MFTextureTileStyle(texture()->getTileStyleU());
|
||||
eTileStyleV = eLib3MFTextureTileStyle(texture()->getTileStyleV());
|
||||
}
|
||||
|
||||
void CTexture2D::SetTileStyleUV (const eLib3MFTextureTileStyle eTileStyleU, const eLib3MFTextureTileStyle eTileStyleV)
|
||||
{
|
||||
texture()->setTileStyleU(NMR::eModelTextureTileStyle(eTileStyleU));
|
||||
texture()->setTileStyleV(NMR::eModelTextureTileStyle(eTileStyleV));
|
||||
}
|
||||
|
||||
eLib3MFTextureFilter CTexture2D::GetFilter ()
|
||||
{
|
||||
return eLib3MFTextureFilter(texture()->getFilter());
|
||||
}
|
||||
|
||||
void CTexture2D::SetFilter (const eLib3MFTextureFilter eFilter)
|
||||
{
|
||||
texture()->setFilter(NMR::eModelTextureFilter(eFilter));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CTexture2DGroup
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_texture2dgroup.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_texture2d.hpp"
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CTexture2DGroup
|
||||
**************************************************************************************************************************/
|
||||
|
||||
NMR::CModelTexture2DGroupResource& CTexture2DGroup::texture2DGroup()
|
||||
{
|
||||
NMR::CModelTexture2DGroupResource* pTexture2dGroup = dynamic_cast<NMR::CModelTexture2DGroupResource*>(resource().get());
|
||||
if (pTexture2dGroup == nullptr)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDTEXTURE2DGROUP);
|
||||
return *pTexture2dGroup;
|
||||
}
|
||||
|
||||
CTexture2DGroup::CTexture2DGroup(NMR::PModelTexture2DGroupResource pResource)
|
||||
: CResource(std::static_pointer_cast<NMR::CModelResource>(pResource))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ITexture2D * CTexture2DGroup::GetTexture2D()
|
||||
{
|
||||
return new CTexture2D(texture2DGroup().getTexture2D());
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CTexture2DGroup::GetCount ()
|
||||
{
|
||||
return texture2DGroup().getCount();
|
||||
}
|
||||
|
||||
void CTexture2DGroup::GetAllPropertyIDs (Lib3MF_uint64 nPropertyIDsBufferSize, Lib3MF_uint64* pPropertyIDsNeededCount, Lib3MF_uint32 * pPropertyIDsBuffer)
|
||||
{
|
||||
Lib3MF_uint32 nCount = texture2DGroup().getCount();
|
||||
|
||||
if (pPropertyIDsNeededCount)
|
||||
*pPropertyIDsNeededCount = nCount;
|
||||
|
||||
if (nPropertyIDsBufferSize >= nCount && pPropertyIDsBuffer) {
|
||||
if (!texture2DGroup().hasResourceIndexMap()) {
|
||||
texture2DGroup().buildResourceIndexMap();
|
||||
}
|
||||
for (Lib3MF_uint32 i = 0; i < nCount; i++) {
|
||||
DWORD nPropertyID;
|
||||
if (texture2DGroup().mapResourceIndexToPropertyID(i, nPropertyID)) {
|
||||
*pPropertyIDsBuffer = nPropertyID;
|
||||
}
|
||||
else {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_INVALIDRESOURCEINDEX);
|
||||
}
|
||||
pPropertyIDsBuffer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CTexture2DGroup::AddTex2Coord (const sLib3MFTex2Coord UVCoordinate)
|
||||
{
|
||||
return texture2DGroup().addUVCoordinate(NMR::MODELTEXTURE2DCOORDINATE({ UVCoordinate.m_U, UVCoordinate.m_V }));
|
||||
}
|
||||
|
||||
sLib3MFTex2Coord CTexture2DGroup::GetTex2Coord (const Lib3MF_uint32 nPropertyID)
|
||||
{
|
||||
NMR::MODELTEXTURE2DCOORDINATE coord = texture2DGroup().getUVCoordinate(nPropertyID);
|
||||
return sLib3MFTex2Coord({ coord.m_dU, coord.m_dV});
|
||||
}
|
||||
|
||||
void CTexture2DGroup::RemoveTex2Coord(const Lib3MF_uint32 nPropertyID)
|
||||
{
|
||||
texture2DGroup().removePropertyID(nPropertyID);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CTexture2DIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_texture2dgroupiterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
#include "lib3mf_texture2dgroup.hpp"
|
||||
// Include custom headers here.
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CTexture2DIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
ITexture2DGroup * CTexture2DGroupIterator::GetCurrentTexture2DGroup()
|
||||
{
|
||||
// Create specific API class
|
||||
return new CTexture2DGroup(std::dynamic_pointer_cast<NMR::CModelTexture2DGroupResource>(GetCurrentResource()));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CTexture2DIterator
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_texture2diterator.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
#include "lib3mf_texture2d.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CTexture2DIterator
|
||||
**************************************************************************************************************************/
|
||||
|
||||
ITexture2D * CTexture2DIterator::GetCurrentTexture2D ()
|
||||
{
|
||||
// Create specific API class
|
||||
return new CTexture2D(std::dynamic_pointer_cast<NMR::CModelTexture2DResource>(GetCurrentResource()));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This file implements utilities for the lib3mf API
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_utils.hpp"
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
|
||||
|
||||
// using namespace Lib3MF::Impl;
|
||||
|
||||
NMR::NMATRIX3 Lib3MF::TransformToMatrix(const sLib3MFTransform Transform)
|
||||
{
|
||||
NMR::NMATRIX3 matrix;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 3; j++)
|
||||
matrix.m_fields[j][i] = Transform.m_Fields[i][j];
|
||||
matrix.m_fields[3][i] = 0.f + 1.0f*(i == 3);
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
sLib3MFTransform Lib3MF::MatrixToTransform(const NMR::NMATRIX3 matrix)
|
||||
{
|
||||
sLib3MFTransform transform;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 3; j++)
|
||||
transform.m_Fields[i][j] = matrix.m_fields[j][i];
|
||||
}
|
||||
return transform;
|
||||
}
|
||||
|
||||
|
||||
eLib3MFEncryptionAlgorithm Lib3MF::translateEncryptionAlgorithm(const NMR::eKeyStoreEncryptAlgorithm algorithm) {
|
||||
if (NMR::eKeyStoreEncryptAlgorithm::AES256_GCM == algorithm)
|
||||
return eLib3MFEncryptionAlgorithm::AES256_GCM;
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_NOTIMPLEMENTED);
|
||||
}
|
||||
NMR::eKeyStoreEncryptAlgorithm Lib3MF::translateEncryptionAlgorithm(const eLib3MFEncryptionAlgorithm algorithm) {
|
||||
if (eLib3MFEncryptionAlgorithm::AES256_GCM == algorithm)
|
||||
return NMR::eKeyStoreEncryptAlgorithm::AES256_GCM;
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_NOTIMPLEMENTED);
|
||||
}
|
||||
|
||||
eLib3MFWrappingAlgorithm Lib3MF::translateWrappingAlgorithm(const NMR::eKeyStoreWrapAlgorithm algorithm) {
|
||||
if (NMR::eKeyStoreWrapAlgorithm::RSA_OAEP == algorithm)
|
||||
return eLib3MFWrappingAlgorithm::RSA_OAEP;
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_NOTIMPLEMENTED);
|
||||
}
|
||||
NMR::eKeyStoreWrapAlgorithm Lib3MF::translateWrappingAlgorithm(const eLib3MFWrappingAlgorithm algorithm) {
|
||||
if (eLib3MFWrappingAlgorithm::RSA_OAEP == algorithm)
|
||||
return NMR::eKeyStoreWrapAlgorithm::RSA_OAEP;
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_NOTIMPLEMENTED);
|
||||
}
|
||||
|
||||
|
||||
|
||||
eLib3MFCompression Lib3MF::translateCompression(bool compression) {
|
||||
if (compression)
|
||||
return eLib3MFCompression::Deflate;
|
||||
return eLib3MFCompression::NoCompression;
|
||||
}
|
||||
|
||||
bool Lib3MF::translateCompression(const eLib3MFCompression compression) {
|
||||
return eLib3MFCompression::Deflate == compression;
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
/*++
|
||||
|
||||
Copyright (C) 2019 3MF Consortium (Original Author)
|
||||
|
||||
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: This is a stub class definition of CWriter
|
||||
|
||||
*/
|
||||
|
||||
#include "lib3mf_writer.hpp"
|
||||
|
||||
// Include custom headers here.
|
||||
#include "lib3mf_interfaceexception.hpp"
|
||||
#include "lib3mf_accessright.hpp"
|
||||
#include "lib3mf_contentencryptionparams.hpp"
|
||||
#include "Common/Platform/NMR_Platform.h"
|
||||
#include "Common/Platform/NMR_ExportStream_Callback.h"
|
||||
#include "Common/Platform/NMR_ExportStream_Memory.h"
|
||||
#include "Common/Platform/NMR_ExportStream_Dummy.h"
|
||||
#include "Common/NMR_SecureContentTypes.h"
|
||||
#include "Common/NMR_SecureContext.h"
|
||||
#include "Model/Classes/NMR_KeyStore.h"
|
||||
#include "Common/NMR_ModelWarnings.h"
|
||||
|
||||
|
||||
|
||||
using namespace Lib3MF::Impl;
|
||||
|
||||
/*************************************************************************************************************************
|
||||
Class definition of CWriter
|
||||
**************************************************************************************************************************/
|
||||
|
||||
CWriter::CWriter(std::string sWriterClass, NMR::PModel model)
|
||||
{
|
||||
m_pWriter = nullptr;
|
||||
|
||||
// Create specified writer instance
|
||||
if (sWriterClass.compare("3mf") == 0) {
|
||||
m_pWriter = std::make_shared<NMR::CModelWriter_3MF_Native>(model);
|
||||
}
|
||||
else if (sWriterClass.compare("stl") == 0) {
|
||||
m_pWriter = std::make_shared<NMR::CModelWriter_STL>(model);
|
||||
}
|
||||
|
||||
if (!m_pWriter)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_WRITERCLASSUNKNOWN);
|
||||
}
|
||||
|
||||
NMR::CModelWriter& CWriter::writer()
|
||||
{
|
||||
return *m_pWriter;
|
||||
}
|
||||
|
||||
void CWriter::WriteToFile (const std::string & sFilename)
|
||||
{
|
||||
setlocale(LC_ALL, "C");
|
||||
NMR::PExportStream pStream = NMR::fnCreateExportStreamInstance(sFilename.c_str());
|
||||
try {
|
||||
writer().exportToStream(pStream);
|
||||
}
|
||||
catch (NMR::CNMRException&e) {
|
||||
if (e.getErrorCode() == NMR_USERABORTED) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
} else if (e.getErrorCode() == NMR_ERROR_DEKDESCRIPTORNOTFOUND
|
||||
|| e.getErrorCode() == NMR_ERROR_KEKDESCRIPTORNOTFOUND) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_SECURECONTEXTNOTREGISTERED);
|
||||
} else throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Lib3MF_uint64 CWriter::GetStreamSize ()
|
||||
{
|
||||
// Write to a special dummy stream just to calculate the size
|
||||
NMR::PExportStreamDummy pStream = std::make_shared<NMR::CExportStreamDummy>();
|
||||
try {
|
||||
writer().exportToStream(pStream);
|
||||
}
|
||||
catch (NMR::CNMRException&e) {
|
||||
if (e.getErrorCode() == NMR_USERABORTED) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
} else if (e.getErrorCode() == NMR_ERROR_DEKDESCRIPTORNOTFOUND
|
||||
|| e.getErrorCode() == NMR_ERROR_KEKDESCRIPTORNOTFOUND) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_SECURECONTEXTNOTREGISTERED);
|
||||
} else throw e;
|
||||
}
|
||||
|
||||
return pStream->getDataSize();
|
||||
}
|
||||
|
||||
#include <cstring>
|
||||
|
||||
void CWriter::WriteToBuffer(Lib3MF_uint64 nBufferBufferSize, Lib3MF_uint64* pBufferNeededCount, Lib3MF_uint8 * pBufferBuffer)
|
||||
{
|
||||
NMR::PExportStreamMemory pStream;
|
||||
if (!momentBuffer || momentBuffer->getDataSize() > nBufferBufferSize) {
|
||||
pStream = std::make_shared<NMR::CExportStreamMemory>();
|
||||
try {
|
||||
writer().exportToStream(pStream);
|
||||
} catch (NMR::CNMRException&e) {
|
||||
if (e.getErrorCode() == NMR_USERABORTED) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
} else if (e.getErrorCode() == NMR_ERROR_DEKDESCRIPTORNOTFOUND
|
||||
|| e.getErrorCode() == NMR_ERROR_KEKDESCRIPTORNOTFOUND) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_SECURECONTEXTNOTREGISTERED);
|
||||
} else throw e;
|
||||
}
|
||||
} else {
|
||||
pStream = momentBuffer;
|
||||
}
|
||||
|
||||
Lib3MF_uint64 cbStreamSize = pStream->getDataSize();
|
||||
if (pBufferNeededCount)
|
||||
*pBufferNeededCount = cbStreamSize;
|
||||
|
||||
if (nBufferBufferSize >= cbStreamSize) {
|
||||
// TODO eliminate this copy, perhaps by allowing CExportStreamMemory to use existing buffers
|
||||
memcpy(pBufferBuffer, pStream->getData(), static_cast<size_t>(cbStreamSize));
|
||||
momentBuffer.reset();
|
||||
} else {
|
||||
momentBuffer = pStream;
|
||||
}
|
||||
}
|
||||
|
||||
void CWriter::WriteToCallback(const Lib3MFWriteCallback pTheWriteCallback, const Lib3MFSeekCallback pTheSeekCallback, const Lib3MF_pvoid pUserData)
|
||||
{
|
||||
NMR::ExportStream_WriteCallbackType lambdaWriteCallback =
|
||||
[pTheWriteCallback](NMR::nfByte* pData, NMR::nfUint64 cbBytes, void* pUserData)
|
||||
{
|
||||
(*pTheWriteCallback)(reinterpret_cast<Lib3MF_uint64>(pData), cbBytes, pUserData );
|
||||
return 0;
|
||||
};
|
||||
|
||||
NMR::ExportStream_SeekCallbackType lambdaSeekCallback =
|
||||
[pTheSeekCallback](NMR::nfUint64 nPosition, void* pUserData)
|
||||
{
|
||||
(*pTheSeekCallback)(nPosition, pUserData);
|
||||
return 0;
|
||||
};
|
||||
|
||||
NMR::PExportStream pStream = std::make_shared<NMR::CExportStream_Callback>(lambdaWriteCallback, lambdaSeekCallback, pUserData);
|
||||
try {
|
||||
writer().exportToStream(pStream);
|
||||
}
|
||||
catch (NMR::CNMRException&e) {
|
||||
if (e.getErrorCode() == NMR_USERABORTED) {
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
}
|
||||
else throw e;
|
||||
}
|
||||
}
|
||||
|
||||
void CWriter::SetProgressCallback(const Lib3MFProgressCallback callback, const Lib3MF_pvoid pUserData)
|
||||
{
|
||||
NMR::Lib3MFProgressCallback lambdaCallback =
|
||||
[callback](int progressStep, NMR::ProgressIdentifier identifier, void* pUserData)
|
||||
{
|
||||
bool ret;
|
||||
(*callback)(&ret, progressStep /100.0f, eLib3MFProgressIdentifier(identifier), pUserData);
|
||||
return ret;
|
||||
};
|
||||
m_pWriter->SetProgressCallback(lambdaCallback, reinterpret_cast<void*>(pUserData));
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CWriter::GetDecimalPrecision()
|
||||
{
|
||||
return m_pWriter->GetDecimalPrecision();
|
||||
}
|
||||
|
||||
void CWriter::SetDecimalPrecision(const Lib3MF_uint32 nDecimalPrecision)
|
||||
{
|
||||
m_pWriter->SetDecimalPrecision(nDecimalPrecision);
|
||||
}
|
||||
|
||||
void Lib3MF::Impl::CWriter::AddKeyWrappingCallback(const std::string & sConsumerID, const Lib3MF::KeyWrappingCallback pTheCallback, const Lib3MF_pvoid pUserData){
|
||||
NMR::KeyWrappingDescriptor descriptor;
|
||||
descriptor.m_sKekDecryptData.m_pUserData = pUserData;
|
||||
descriptor.m_fnWrap =
|
||||
[this, pTheCallback](
|
||||
std::vector<NMR::nfByte> const & plain,
|
||||
std::vector<NMR::nfByte> & cipher,
|
||||
NMR::KeyWrappingContext & ctx) {
|
||||
|
||||
std::shared_ptr<IAccessRight> pAccessRight = std::make_shared<CAccessRight>(ctx.m_pAccessRight);
|
||||
IBase * pBaseEntity(nullptr);
|
||||
pBaseEntity = pAccessRight.get();
|
||||
Lib3MF_AccessRight entityHandle = pBaseEntity;
|
||||
|
||||
Lib3MF_uint64 needed = 0;
|
||||
Lib3MF_uint64 result = 0;
|
||||
(*pTheCallback)(entityHandle, plain.size(), plain.data(), 0,
|
||||
&needed, nullptr, ctx.m_pUserData, &result);
|
||||
if (result == 0)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
|
||||
cipher.resize(needed, 0);
|
||||
|
||||
result = 0;
|
||||
(*pTheCallback)(entityHandle, plain.size(), plain.data(), plain.size(),
|
||||
nullptr, cipher.data(), ctx.m_pUserData, &result);
|
||||
if (result == 0)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
return (NMR::nfUint64)result;
|
||||
};
|
||||
writer().secureContext()->addKekCtx(sConsumerID, descriptor);
|
||||
}
|
||||
|
||||
void Lib3MF::Impl::CWriter::SetContentEncryptionCallback(const Lib3MF::ContentEncryptionCallback pTheCallback, const Lib3MF_pvoid pUserData)
|
||||
{
|
||||
NMR::ContentEncryptionDescriptor descriptor;
|
||||
descriptor.m_sDekDecryptData.m_pUserData = pUserData;
|
||||
descriptor.m_fnCrypt = [this, pTheCallback](
|
||||
NMR::nfUint64 size,
|
||||
NMR::nfByte const * plain,
|
||||
NMR::nfByte * cipher,
|
||||
NMR::ContentEncryptionContext & ctx) {
|
||||
std::shared_ptr<CContentEncryptionParams> pCekParams = std::make_shared<CContentEncryptionParams>(ctx.m_sParams);
|
||||
IBase * pBaseEntity(nullptr);
|
||||
pBaseEntity = pCekParams.get();
|
||||
Lib3MF_ContentEncryptionParams entityHandle = pBaseEntity;
|
||||
Lib3MF_uint64 result = 0;
|
||||
(*pTheCallback)(entityHandle, (Lib3MF_uint64)size, plain, (Lib3MF_uint64)size, nullptr, cipher, ctx.m_pUserData, &result);
|
||||
if (result == 0)
|
||||
throw ELib3MFInterfaceException(LIB3MF_ERROR_CALCULATIONABORTED);
|
||||
return (NMR::nfUint64)result;
|
||||
};
|
||||
m_pWriter->secureContext()->setDekCtx(descriptor);
|
||||
}
|
||||
|
||||
void CWriter::SetStrictModeActive(const bool bStrictModeActive) {
|
||||
if (bStrictModeActive)
|
||||
writer().warnings()->setCriticalWarningLevel(NMR::mrwInvalidOptionalValue);
|
||||
else
|
||||
writer().warnings()->setCriticalWarningLevel(NMR::mrwFatal);
|
||||
}
|
||||
|
||||
bool CWriter::GetStrictModeActive() {
|
||||
return writer().warnings()->getCriticalWarningLevel() == NMR::mrwInvalidOptionalValue;
|
||||
}
|
||||
|
||||
std::string CWriter::GetWarning(const Lib3MF_uint32 nIndex, Lib3MF_uint32 & nErrorCode) {
|
||||
auto warning = writer().warnings()->getWarning(nIndex);
|
||||
nErrorCode = warning->getErrorCode();
|
||||
return warning->getMessage();
|
||||
}
|
||||
|
||||
Lib3MF_uint32 CWriter::GetWarningCount() {
|
||||
return writer().warnings()->getWarningCount();
|
||||
}
|
||||
Reference in New Issue
Block a user