Skip to content

Commit 8757243

Browse files
NC-6947: Add progress callback for model IO
Includes example in SDK, UnitTest, and documentation - Make progress more granular - Add UnitTest_ProgressCallback - Add intra-model updates (their actual progress is monotonically increasing, but actually made up.)
1 parent 9ffbfda commit 8757243

File tree

58 files changed

+1019
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1019
-73
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ project (lib3MF)
88

99
# Define Version
1010
set(LIB3MF_VERSION_MAJOR 1) # increase on every backward-compatibility breaking change of the API
11-
set(LIB3MF_VERSION_MINOR 0) # increase on every backward compatible change of the API
12-
set(LIB3MF_VERSION_MICRO 9) # increase on on every change that does not alter the API
11+
set(LIB3MF_VERSION_MINOR 1) # increase on every backward compatible change of the API
12+
set(LIB3MF_VERSION_MICRO 3) # increase on on every change that does not alter the API
1313

1414
set(CMAKE_INSTALL_BINDIR bin CACHE PATH "directory for installing binary files")
1515
set(CMAKE_INSTALL_LIBDIR lib CACHE PATH "directory for installing library files")
@@ -99,7 +99,7 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME}_s PROPERTIES PREFIX "" IMPORT_PREFIX "")
9999
if (UNIX)
100100
target_compile_options(${PROJECT_NAME}_s PUBLIC "-fPIC")
101101
# Uncomment the following to but the version info into the .so-file.
102-
SET_TARGET_PROPERTIES(${PROJECT_NAME}_s PROPERTIES VERSION "${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB3MF_VERSION_MICRO}.${BUILD_NUMBER}")
102+
SET_TARGET_PROPERTIES(${PROJECT_NAME}_s PROPERTIES VERSION "${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB3MF_VERSION_MICRO}")
103103
SET_TARGET_PROPERTIES(${PROJECT_NAME}_s PROPERTIES SOVERSION "${LIB3MF_VERSION_MAJOR}")
104104
if (NOT APPLE)
105105
SET_TARGET_PROPERTIES(${PROJECT_NAME}_s PROPERTIES LINK_FLAGS -s)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*++
2+
3+
Copyright (C) 2018 Autodesk Inc.
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
1. Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
Abstract: Progress Monitor
28+
29+
--*/
30+
31+
#ifndef __NMR_PROGRESSMONITOR
32+
#define __NMR_PROGRESSMONITOR
33+
34+
#include "Common/3MF_ProgressTypes.h"
35+
36+
#include <memory>
37+
#include <mutex>
38+
#include <stack>
39+
40+
namespace NMR
41+
{
42+
#define PROGRESS_SLICEUPDATE 1000
43+
#define PROGRESS_NODEUPDATE 100000
44+
#define PROGRESS_TRIANGLEUPDATE 100000
45+
#define PROGRESS_READUPDATE 20000
46+
#define PROGRESS_READSLICESUPDATE 100
47+
#define PROGRESS_READBUFFERUPDATE 100
48+
49+
class CProgressMonitor
50+
{
51+
public:
52+
CProgressMonitor();
53+
void SetProgressCallback(Lib3MFProgressCallback callback, void* userData);
54+
void ClearProgressCallback();
55+
// Returns true if the last callback call returned false
56+
bool WasAborted();
57+
// If Progress() returns false, the task calling it should try to abort
58+
bool QueryCancelled();
59+
bool Progress(double progress, ProgressIdentifier identifier);
60+
61+
static void GetProgressMessage(ProgressIdentifier progressIdentifier, const char ** progressString);
62+
63+
void PushLevel(double relativeStart, double relativeEnd);
64+
std::pair<double, double> PopLevel();
65+
void ResetLevels();
66+
private:
67+
Lib3MFProgressCallback m_progressCallback;
68+
void* m_userData;
69+
bool m_lastCallbackResult;
70+
std::stack<std::pair<double, double>> m_levels;
71+
72+
std::pair<double, double> Level();
73+
std::mutex m_callbackMutex;
74+
};
75+
76+
typedef std::shared_ptr <CProgressMonitor> PProgressMonitor;
77+
};
78+
79+
#endif // __NMR_PROGRESSMONITOR

Include/Common/3MF_ProgressTypes.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*++
2+
3+
Copyright (C) 2018 Autodesk Inc.
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
1. Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
Abstract: Progress Types
28+
29+
--*/
30+
31+
#pragma once
32+
33+
34+
namespace NMR
35+
{
36+
enum ProgressIdentifier {
37+
PROGRESS_QUERYCANCELED = 0,
38+
PROGRESS_DONE,
39+
PROGRESS_CLEANUP,
40+
PROGRESS_READSTREAM,
41+
PROGRESS_EXTRACTOPCPACKAGE,
42+
PROGRESS_READNONROOTMODELS,
43+
PROGRESS_READROOTMODEL,
44+
PROGRESS_READRESOURCES,
45+
PROGRESS_READMESH,
46+
PROGRESS_READSLICES,
47+
PROGRESS_READBUILD,
48+
PROGRESS_CREATEOPCPACKAGE,
49+
PROGRESS_WRITEMODELSTOSTREAM,
50+
PROGRESS_WRITEROOTMODEL,
51+
PROGRESS_WRITENONROOTMODELS,
52+
PROGRESS_WRITEATTACHMENTS,
53+
PROGRESS_WRITECONTENTTYPES,
54+
PROGRESS_WRITENOBJECTS,
55+
PROGRESS_WRITENODES,
56+
PROGRESS_WRITETRIANGLES,
57+
PROGRESS_WRITESLICES
58+
};
59+
60+
// !!! Matches dll interface type, always modify both
61+
// If the first parameter is -1, it does not indicate progress;In that case
62+
// it must only be used to stop the execution of the calling function.
63+
typedef bool(*Lib3MFProgressCallback)(int, ProgressIdentifier, void*);
64+
};

Include/Common/MeshInformation/NMR_MeshInformationContainer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ This class provides a memory container for holding the texture information state
3535
#define __NMR_MESHINFORMATIONCONTAINER
3636

3737
#include "Common/MeshInformation/NMR_MeshInformationTypes.h"
38-
#include "Common/NMR_ErrorConst.h"
3938
#include "Common/NMR_Types.h"
4039
#include "Common/NMR_Local.h"
4140

Include/Common/NMR_ErrorConst.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ NMR_ErrorConst.h defines all error code constants.
3636
// This is the output value of a "uncatched exception"
3737
#define NMR_GENERICEXCEPTIONSTRING "uncatched exception"
3838

39+
/*-------------------------------------------------------------------
40+
Success / user interaction (0x0XXX)
41+
-------------------------------------------------------------------*/
42+
3943
// Function has suceeded, there has been no error
40-
#define NMR_SUCCESS 0
44+
#define NMR_SUCCESS 0x0
45+
46+
// Function was aborted by user
47+
#define NMR_USERABORTED 0x0001
4148

4249
/*-------------------------------------------------------------------
4350
General error codes (0x1XXX)

Include/Common/Platform/NMR_Platform.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ classes.
3939
#include "Common/Platform/NMR_ExportStream.h"
4040
#include "Common/Platform/NMR_XmlReader.h"
4141
#include "Common/Platform/NMR_XmlWriter.h"
42+
#include "Common/3MF_ProgressMonitor.h"
4243

4344
namespace NMR {
4445

4546
PImportStream fnCreateImportStreamInstance (_In_ const nfWChar * pwszFileName);
4647
PExportStream fnCreateExportStreamInstance (_In_ const nfWChar * pwszFileName);
47-
PXmlReader fnCreateXMLReaderInstance (_In_ PImportStream pImportStream);
48-
PXmlWriter fnCreateXMLWriterInstance (_In_ PExportStream pExportStream);
48+
PXmlReader fnCreateXMLReaderInstance (_In_ PImportStream pImportStream, CProgressMonitor * pProgressMonitor);
49+
PXmlWriter fnCreateXMLWriterInstance (_In_ PExportStream pExportStream, CProgressMonitor * pProgressMonitor);
4950

5051
}
5152

Include/Common/Platform/NMR_XmlReader_Native.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ NMR_XMLReader_Native.h defines a XML reader class with a native XML parsing impl
3434
#define __NMR_XMLREADER_NATIVE
3535

3636
#include "Common/Platform/NMR_XmlReader.h"
37+
#include "Common/3MF_ProgressMonitor.h"
3738

3839
#include <memory>
3940
#include <vector>
@@ -74,6 +75,9 @@ namespace NMR {
7475

7576
class CXmlReader_Native : public CXmlReader {
7677
private:
78+
nfUint32 m_progressCounter;
79+
CProgressMonitor* m_pProgressMonitor;
80+
7781
nfUint32 m_cbBufferCapacity;
7882
// Allocated memory of current and next chunk
7983
std::vector<nfWChar> m_UTF16Buffer1;
@@ -152,7 +156,7 @@ namespace NMR {
152156
void pushEntity(_In_ nfWChar * pszwEntityStartChar, _In_ nfWChar * pszwEntityEndDelimiter, _In_ nfWChar * pszwNextEntityChar, _In_ nfByte nType, _In_ nfBool bParseForNamespaces, _In_ nfBool bEntityIsFinished);
153157

154158
public:
155-
CXmlReader_Native(_In_ PImportStream pImportStream, _In_ nfUint32 cbBufferCapacity);
159+
CXmlReader_Native(_In_ PImportStream pImportStream, _In_ nfUint32 cbBufferCapacity, _In_ CProgressMonitor* pProgressMonitor);
156160
~CXmlReader_Native();
157161

158162
virtual void GetValue(_Outptr_result_buffer_maybenull_(*pcwchValue + 1) const nfWChar ** ppwszValue, _Out_opt_ nfUint32 *pcwchValue);

Include/Model/COM/NMR_COMInterface_ModelFactory.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ COM Interface Implementation for the COM Model Factory class.
3737

3838
#include "Model/COM/NMR_COMInterfaces.h"
3939
#include "Model/Classes/NMR_Model.h"
40+
#include "Common/3MF_ProgressTypes.h"
4041

4142
namespace NMR {
4243

@@ -56,11 +57,13 @@ namespace NMR {
5657
LIB3MFMETHOD(GetLastError) (_Out_ DWORD * pErrorCode, _Outptr_opt_ LPCSTR * pErrorMessage);
5758

5859
LIB3MFMETHOD(CreateModel) (_Outptr_ ILib3MFModel ** ppModel);
60+
5961
LIB3MFMETHOD(GetSpecVersion) (_Out_ DWORD * pMajorVersion, _Out_ DWORD * pMinorVersion);
6062
LIB3MFMETHOD(GetInterfaceVersion) (_Out_ DWORD * pInterfaceVersionMajor, _Out_ DWORD * pInterfaceVersionMinor, _Out_ DWORD * pInterfaceVersionMicro);
6163
LIB3MFMETHOD(QueryExtension) (_In_z_ LPCWSTR pwszExtensionUrl, _Out_ BOOL * pbIsSupported, _Out_opt_ DWORD * pExtensionInterfaceVersion);
6264
LIB3MFMETHOD(QueryExtensionUTF8) (_In_z_ LPCSTR pszExtensionUrl, _Out_ BOOL * pbIsSupported, _Out_opt_ DWORD * pExtensionInterfaceVersion);
63-
65+
66+
LIB3MFMETHOD(RetrieveProgressMessage) (_In_ int progressIdentifier, _Out_ LPCSTR * progressMessage);
6467

6568
CCOMModelFactory();
6669
};

Include/Model/COM/NMR_COMInterface_ModelReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ namespace NMR {
7474

7575
LIB3MFMETHOD(ReadFromCallback) (_In_ void * pReadCallback, _In_ nfUint64 nStreamSize, _In_opt_ void * pSeekCallback, _In_opt_ void * pUserData);
7676

77+
LIB3MFMETHOD(SetProgressCallback) (_In_ void * callback, _In_ void* userData);
78+
7779
CCOMModelReader();
7880

7981
void setReader(_In_ PModelReader pModelReader);

Include/Model/COM/NMR_COMInterface_ModelWriter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ namespace NMR {
6666
LIB3MFMETHOD(WriteToBuffer) (_Out_ BYTE * pBuffer, _In_ ULONG64 cbBufferSize);
6767
LIB3MFMETHOD(WriteToCallback) (_In_ void * pWriteCallback, _In_opt_ void * pSeekCallback, _In_opt_ void * pUserData);
6868

69+
LIB3MFMETHOD(SetProgressCallback) (_In_ void * callback, _In_ void* userData);
70+
6971
CCOMModelWriter();
7072
void setWriter(_In_ PModelWriter pModelWriter);
7173
};

0 commit comments

Comments
 (0)