1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2021, assimp team
6 
7 
8 All rights reserved.
9 
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the
12 following conditions are met:
13 
14 * Redistributions of source code must retain the above
15   copyright notice, this list of conditions and the
16   following disclaimer.
17 
18 * Redistributions in binary form must reproduce the above
19   copyright notice, this list of conditions and the
20   following disclaimer in the documentation and/or other
21   materials provided with the distribution.
22 
23 * Neither the name of the assimp team, nor the names of its
24   contributors may be used to endorse or promote products
25   derived from this software without specific prior
26   written permission of the assimp team.
27 
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 
40 ----------------------------------------------------------------------
41 */
42 
43 /** @file ProgressHandler.hpp
44  *  @brief Abstract base class 'ProgressHandler'.
45  */
46 #pragma once
47 #ifndef AI_PROGRESSHANDLER_H_INC
48 #define AI_PROGRESSHANDLER_H_INC
49 
50 #ifdef __GNUC__
51 #   pragma GCC system_header
52 #endif
53 
54 #include <assimp/types.h>
55 
56 namespace Assimp {
57 
58 // ------------------------------------------------------------------------------------
59 /** @brief CPP-API: Abstract interface for custom progress report receivers.
60  *
61  *  Each #Importer instance maintains its own #ProgressHandler. The default
62  *  implementation provided by Assimp doesn't do anything at all. */
63 class ASSIMP_API ProgressHandler
64 #ifndef SWIG
65     : public Intern::AllocateFromAssimpHeap
66 #endif
67 {
68 protected:
69     /// @brief  Default constructor
ProgressHandler()70     ProgressHandler () AI_NO_EXCEPT {
71         // empty
72     }
73 
74 public:
75     /// @brief  Virtual destructor.
~ProgressHandler()76     virtual ~ProgressHandler () {
77     }
78 
79     // -------------------------------------------------------------------
80     /** @brief Progress callback.
81      *  @param percentage An estimate of the current loading progress,
82      *    in percent. Or -1.f if such an estimate is not available.
83      *
84      *  There are restriction on what you may do from within your
85      *  implementation of this method: no exceptions may be thrown and no
86      *  non-const #Importer methods may be called. It is
87      *  not generally possible to predict the number of callbacks
88      *  fired during a single import.
89      *
90      *  @return Return false to abort loading at the next possible
91      *   occasion (loaders and Assimp are generally allowed to perform
92      *   all needed cleanup tasks prior to returning control to the
93      *   caller). If the loading is aborted, #Importer::ReadFile()
94      *   returns always nullptr.
95      *   */
96     virtual bool Update(float percentage = -1.f) = 0;
97 
98     // -------------------------------------------------------------------
99     /** @brief Progress callback for file loading steps
100      *  @param numberOfSteps The number of total post-processing
101      *   steps
102      *  @param currentStep The index of the current post-processing
103      *   step that will run, or equal to numberOfSteps if all of
104      *   them has finished. This number is always strictly monotone
105      *   increasing, although not necessarily linearly.
106      *
107      *  @note This is currently only used at the start and the end
108      *   of the file parsing.
109      *   */
UpdateFileRead(int currentStep,int numberOfSteps)110     virtual void UpdateFileRead(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) {
111         float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f;
112         Update( f * 0.5f );
113     }
114 
115     // -------------------------------------------------------------------
116     /** @brief Progress callback for post-processing steps
117      *  @param numberOfSteps The number of total post-processing
118      *   steps
119      *  @param currentStep The index of the current post-processing
120      *   step that will run, or equal to numberOfSteps if all of
121      *   them has finished. This number is always strictly monotone
122      *   increasing, although not necessarily linearly.
123      *   */
UpdatePostProcess(int currentStep,int numberOfSteps)124     virtual void UpdatePostProcess(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) {
125         float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f;
126         Update( f * 0.5f + 0.5f );
127     }
128 
129 
130     // -------------------------------------------------------------------
131     /** @brief Progress callback for export steps.
132      *  @param numberOfSteps The number of total processing
133      *   steps
134      *  @param currentStep The index of the current post-processing
135      *   step that will run, or equal to numberOfSteps if all of
136      *   them has finished. This number is always strictly monotone
137      *   increasing, although not necessarily linearly.
138      *   */
UpdateFileWrite(int currentStep,int numberOfSteps)139     virtual void UpdateFileWrite(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) {
140         float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f;
141         Update(f * 0.5f);
142     }
143 }; // !class ProgressHandler
144 
145 // ------------------------------------------------------------------------------------
146 
147 } // Namespace Assimp
148 
149 #endif // AI_PROGRESSHANDLER_H_INC
150