Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
ProcessProgressInfo.h
1#ifndef PROCESSPROGRESSINFO_H
2#define PROCESSPROGRESSINFO_H
3
4#ifdef _MSC_VER
5#pragma once
6#endif // _MSC_VER
7
8#include "XThreadSync.h"
9
10BEGIN_MOOTOOLS_NAMESPACE
11
12 typedef enum _ProgressStep
13 {
14 PROGRESS_INIT = 0x01,
15 PROGRESS_POS_CHANGED = 0x02,
16 PROGRESS_RANGE_CHANGED = 0x04,
17 PROGRESS_TEXT_CHANGED = 0x08,
18 PROGRESS_CHECK_CANCEL = 0x10,
19 PROGRESS_END = 0x20,
21
23 typedef bool (*ProcessProgressCallback)(unsigned int step, const ProcessProgressInfo& info, void *data);
24
25 DLL_TOOLSFUNCTION bool progressCallCallback(unsigned int step, const ProcessProgressInfo& info);
26 DLL_TOOLSFUNCTION void progressPushCallback(ProcessProgressCallback callback, void *data);
27 DLL_TOOLSFUNCTION bool progressPopCallback();
28 DLL_TOOLSFUNCTION ProcessProgressCallback progressGetCallback(void *&data);
29 DLL_TOOLSFUNCTION bool progressUserCancel();
30
32 {
33 protected:
34 mutable CXCriticalSection threadLock;
35 CXString title, text;
36 int min, max, pos;
37
38 public:
39 ProcessProgressInfo(int min = 0, int max = 100, int pos = 0)
40 {
41 this->min = min;
42 this->max = max;
43 this->pos = pos;
44 };
45
47 {
48 progressCallCallback(PROGRESS_END, *this);
49 };
50
51 void SetRange(int refmin, int refmax)
52 {
53 CXSingleLock lock(&threadLock);
54 this->min = refmin;
55 this->max = refmax;
56 pos = min;
57 };
58
59 void GetRange(int& refmin, int& refmax) const
60 {
61 refmin = min;
62 refmax = max;
63 }
64
65 int GetRange() const
66 {
67 return max - min;
68 }
69
70 void AddMax(int max)
71 {
72 CXSingleLock lock(&threadLock);
73 this->max += max;
74 }
75
76 void AddPos(int pos)
77 {
78 CXSingleLock lock(&threadLock);
79 this->pos += pos;
80 }
81
82 void SetTitle(const CXString& reftitle)
83 {
84 CXSingleLock lock(&threadLock);
85 this->title = reftitle;
86 };
87
88 CXString GetTitle() const
89 {
90 CXSingleLock lock(&threadLock);
91 return title;
92 }
93
94 void SetText(const CXString& reftext)
95 {
96 CXSingleLock lock(&threadLock);
97 this->text = reftext;
98 };
99
100 CXString GetText() const
101 {
102 CXSingleLock lock(&threadLock);
103 return text;
104 }
105
106 void SetPos(int refpos)
107 {
108 CXSingleLock lock(&threadLock);
109 this->pos = refpos;
110 }
111
112 int GetPos() const
113 {
114 return pos;
115 }
116
117 float GetPercent() const
118 {
119 CXSingleLock lock(&threadLock);
120 return (float)pos/(float)(max-min);
121 }
122
123 };
124
125 #define PROGRESS_CALLBACK_INIT(title, text, min, max) \
126 bool processProgressCancel = FALSE; \
127 ProcessProgressInfo progressCallbackInfo; \
128 progressCallbackInfo.SetTitle(title); \
129 progressCallbackInfo.SetText(text); \
130 progressCallbackInfo.SetRange((int)min, (int)max); \
131 progressCallCallback(PROGRESS_INIT|PROGRESS_POS_CHANGED|PROGRESS_RANGE_CHANGED|PROGRESS_TEXT_CHANGED, progressCallbackInfo);
132
133 #define PROGRESS_CALLBACK_INIT2(title, text) \
134 bool processProgressCancel = FALSE; \
135 ProcessProgressInfo progressCallbackInfo; \
136 progressCallbackInfo.SetTitle(title); \
137 progressCallbackInfo.SetText(text); \
138 progressCallCallback(PROGRESS_INIT|PROGRESS_TEXT_CHANGED, progressCallbackInfo);
139
140 #define PROGRESS_SET_RANGE(min, max) \
141 progressCallbackInfo.SetRange((int)min, (int)max); \
142 progressCallCallback(PROGRESS_RANGE_CHANGED, progressCallbackInfo);
143
144 #define PROGRESS_SET_POS(pos) \
145 progressCallbackInfo.SetPos((int)pos); \
146 progressCallCallback(PROGRESS_POS_CHANGED, progressCallbackInfo);
147
148 #define PROGRESS_USER_CANCEL processProgressCancel
149
150 #define PROGRESS_CHECK_CANCEL(action) \
151 if (processProgressCancel) \
152 action;
153
154 #define PROGRESS_STEP(pos, modulo, action) \
155 XASSERT(modulo); \
156 if (((int)pos) % modulo) \
157 { \
158 PROGRESS_SET_POS(pos) \
159 processProgressCancel = progressCallCallback(PROGRESS_POS_CHANGED|PROGRESS_CHECK_CANCEL, progressCallbackInfo); \
160 if (processProgressCancel) \
161 action; \
162 }
163
164END_MOOTOOLS_NAMESPACE
165
166#endif // PROCESSPROGRESSINFO_H
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Definition XThreadSync.h:20
Definition XThreadSync.h:38
Definition ProcessProgressInfo.h:32