-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSave_Image_Thread.hh
311 lines (246 loc) · 9.12 KB
/
Save_Image_Thread.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/* Save_Image_Thread
HiROC CVS ID: $Id: Save_Image_Thread.hh,v 1.6 2012/06/15 01:16:07 castalia Exp $
Copyright (C) 2011 Arizona Board of Regents on behalf of the
Planetary Image Research Laboratory, Lunar and Planetary Laboratory at
the University of Arizona.
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License, version 2.1,
as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*******************************************************************************/
#ifndef HiView_Save_Image_Thread_hh
#define HiView_Save_Image_Thread_hh
#include <QThread>
#include <QMutex>
#include <QString>
// Forward renferences.
class QDialog;
class QHBoxLayout;
class QLabel;
class QMessageBox;
namespace UA::HiRISE
{
// Forward references.
class Plastic_Image;
class Activity_Indicator;
/** A <i>Save_Image_Thread</i> is a QThread subclass that saves a
Plastic_Image to a file.
@author Bradford Castalia, UA/HiROC
@version $Revision: 1.6 $
*/
class Save_Image_Thread
: public QThread
{
// Qt Object declaration.
Q_OBJECT
public:
/*==============================================================================
Constants
*/
//! Class identification name with source code version and date.
static const char* const
ID;
//! The {@link save_sequence() save sequence} values.
enum Save_Sequence
{
SAVE_IMAGE_DONE,
SAVE_IMAGE_RENDER,
SAVE_IMAGE_WRITE
};
/*==============================================================================
Constructors
*/
Save_Image_Thread (QObject* parent = NULL);
virtual ~Save_Image_Thread ();
/*==============================================================================
Accessors
*/
/* Specify the image and the file pathname and image file format to
be used when saving.
@param plastic_image A pointer to the Plastic_Image to be saved.
If NULL, the current {@link image() image} will be used.
@param pathname The pathname to the file where the image is to
be saved. If empty the current {@link image_pathname() pathname}
will be used.
@param format The name of the image file format to use when saving
the file. If empty the current {@link image_format() format} will
be used.
@return true if the required Plastic_Image, image file pathname
and format are all valid, whether they were set by the current
method call or not. By calling this method with a single NULL
argument one can test if the Save_Image_Thread has all the
required information without affecting any information that has
already been set. false will be returned if any required information
is invalid.
@see invalidate()
@see save_image(Plastic_Image*, const QString&, const QString&)
*/
bool image (Plastic_Image* plastic_image,
const QString& pathname = QString (), const QString& format = QString ());
inline Plastic_Image* image () const
{return Image;}
inline QString image_pathname () const
{return Pathname;}
inline QString image_format () const
{return Format;}
/** Invalidate any previous image save information.
The {@link image() image} is set to NULL and the {@link image_pathname()
pathname} and {@link image_format() format} are cleared.
@see image(Plastic_Image*, const QString&, const QString&)
*/
void invalidate ();
/** Get the current sequence state for the save operation.
The thread will be in one of three {@link #Save_Sequence states}:
<dl>
<dt>SAVE_IMAGE_DONE
<dd>The thread is done with the save operation; or no save operation
has yet been started. The thread may still be running while it is
in this state.
<dt>SAVE_IMAGE_RENDER
<dd>The {@link image() image} is being updated which causes all
rendering operations pending for the image, if any, to be
applied. The save operation may be successfully {@link cancel()
canceled} during this sequence.
<dt>SAVE_IMAGE_WRITE
<dd>If the image update rendering succeeded the image is written
to the file at the current {@link image_pathname() pathname} using
the {@link image_format() image file format}. The save operation
may not be canceled during this sequence.
</dl>
@return A Save_Sequence value.
*/
Save_Sequence save_sequence () const;
/** Get the completion status of the last image save operation.
@return true if the last image save operation completed successfully;
false if no save operation has yet been started; no image,
pathname or format was specified; the last save operation was
canceled before image rendering updated completed, or the image
rendering update failed; or writing the image file failed.
@see save_image(Plastic_Image*, const QString&, const QString&)
@see failure_message()
*/
bool image_saved () const;
QString failure_message () const;
/*==============================================================================
Thread run
*/
/** Display a save activity dialog and start the thread.
This method provides a modeless save activity dialog with the name of
image file format and pathname along with an activity inidicator that
can be clicked to {@link cancel() cancel} the operation. After
showing the dialog the thread is started to save the image that was
specified in the constructor to the pathname with the image file
format specified.
<b>N.B.</b>: Using the thread's start method will also save the image
to the pathname with the specified image file format, but in that
case no activity dialog will be shown.
This method returns once the thread has been started. If the thread
is already running nothing is done.
@param plastic_image A pointer to the Plastic_Image to be saved.
If NULL, the current {@link image() image} will be used.
@param pathname The pathname to the file where the image is to
be saved. If empty the current {@link image_pathname() pathname}
will be used.
@param format The name of the image file format to use when saving
the file. If empty the current {@link image_format() format} will
be used.
@return true if the save image thread was started; false otherwise.
@see image(Plastic_Image*, const QString&, const QString&)
*/
bool save_image (Plastic_Image* plastic_image = NULL,
const QString& pathname = QString (), const QString& format = QString ());
protected:
/** Begin running the thread.
The {@link saved() saved} flag is set to false. If no {@link image()
image} has been specified or either the pathname or image file format
are empty, nothing is done. Otherwise the image save operation is
executed.
The image save operation includes two {@link save_sequence()
sequences}:
<dl>
<dt>SAVE_IMAGE_RENDER
The image is
first updated which causes all rendering operations pending for
the image to be applied. If this succeeds
*/
virtual void run ();
/*==============================================================================
Qt signals
*/
public:
signals:
/** Signals that the image save operation is done.
@param completed true if the image was {@link saved() saved};
otherwise false.
*/
void done (bool completed);
/** Signals the completion status of a {@link cancel() cancel} request.
@param completed true if the saving operation was canceled or was
not active; false if the image file is being written which can
not be canceled.
*/
void canceled (bool completed);
/*==============================================================================
Qt slots
*/
public slots:
bool show_dialog (bool enabled);
/** Cancel the thread's image save operation.
If the thread is not running nothing is done.
If the thread is running and it is in the {@link #SAVE_IMAGE_RENDER}
{@link save_sequence() save sequence} the image rendering is canceled.
While the thread is in the {@link #SAVE_IMAGE_WRITE} sequence it can
not be canceled.
The {@link canceled(bool) canceled} signal is emitted with the
completion status. If image saving was started by the {@link
save_image(Plastic_Image*, const QString&, const QString&) save_image}
method the activity dialog will be stopped and hidden when
the thread is finished. If, however, the image file is being written
an information dialog noting this is shown along with the activity
dialog until the thread is finished (or the user dismisses the
information dialog).
@return true if the saving operation was canceled or was not active;
false if the image file is being written which can not be canceled.
*/
bool cancel ();
private slots:
void thread_finished ();
void thread_terminated ();
void save_canceled (bool);
/*==============================================================================
Data
*/
private:
Plastic_Image
*Image;
QString
Pathname,
Format;
QDialog
*Dialog;
QHBoxLayout
*Dialog_Layout;
Activity_Indicator
*Activity;
QLabel
*Format_Label,
*Pathname_Label;
QMessageBox
*Message;
mutable QMutex
Sequence_Lock;
Save_Sequence
Sequence;
bool
Saved;
QString
Failure_Message;
};
} // namespace UA::HiRISE
#endif